[email protected]@EDate传入后在Set语句中应该如何写才能不出错
ALTER proc Get_adjscx
(
@bt varchar(4),
@ddid varchar(30),
@zdid varchar(30),
@Bdate varchar(10),
@Edate varchar(10)
)
as
DECLARE @SqlStr varchar(200)
Set @SqlStr= 'select * from bl_idx where BDate> = '[email protected]+ ' and Bdate <= '[email protected]
select @SqlStr
if @bt <> ' '
Set @[email protected]+ ' and [email protected] '
if @ddid <> ' '
Set @[email protected]+ ' and [email protected] '
if @zdid <> ' '
Set @[email protected]+ ' and [email protected] '
exec(@SqlStr)
go
------解决方案--------------------
ALTER proc Get_adjscx
(
@bt varchar(4),
@ddid varchar(30),
@zdid varchar(30),
@Bdate varchar(10),
@Edate varchar(10)
)
as
DECLARE @SqlStr varchar(200)
Set @SqlStr= 'select * from bl_idx where BDate> = ' ' '[email protected]+ ' ' ' and Bdate <= ' ' '[email protected]+ ' ' ' '
select @SqlStr
if @bt <> ' '
Set @[email protected]+ ' and bt= '[email protected]
if @ddid <> ' '
Set @[email protected]+ ' and ddid= '[email protected]
if @zdid <> ' '
Set @[email protected]+ ' and zdid= '[email protected]
exec(@SqlStr)
go
------解决方案--------------------
规定:日期要用单引号括起来,当字符串中有单引号时,必须将单引号换成二个单引号.
Set @SqlStr= 'select * from bl_idx where BDate> = ' ' '[email protected]+ ' ' ' and Bdate <= ' ' '[email protected] + ' ' ' '