日期:2014-05-18  浏览次数:20564 次

sql server 语句中的引号问题
大家好,我的问题是:

前台传一个日期,在后台用存储过程接受 (如用变量@ymd)

然后执行 select * from A where date between ''+@ymd + ' 00:00:00'+and +''@ymd +' 23:59:59'

编译不能通过,请各位指点一下。多谢!

------解决方案--------------------
SQL code

select * from A where date between +@ymd + ' 00:00:00' and @ymd +' 23:59:59'

------解决方案--------------------
SQL code

select * from A where Dates between @ymd+' 00:00:00' and @ymd +' 23:59:59'
or
create proc p_test
@ymd varchar(12)
as
declare @sql varchar(max),@sql2 varchar(max)
set @sql='
select * from A where date between '''+@ymd + ' 00:00:00'''+'and ''' +@ymd +' 23:59:59'''
print @sql---select * from A where date between '2012-04-18 00:00:00'and '2012-04-18 23:59:59'