我写了个存储过程,然后定义了一个@datewhere varchar(50),我从程序里面传进来的就是
'scan_start_time ='2005-12-22 00:00:00' or scan_start_time='2005-12-22 01:00:00''
在数据库中我用了
exec('select * from #tmp where('+@datewhere+') order by scan_start_time' )
程序老报错,说什么order by前有引号没有关闭,然后请顺便给我讲解下在用exec的时候,变量使用有些什么规则,比如上面写成exec('select * from #tmp where'+@datewhere+' order by scan_start_time' )
有什么区别呢,对这里自己有点迷糊