菜鸟关于语法的简单问题
CREATE PROC CD_UpPic
@ID int,
@PicType varchar(20),
@PicName varchar(200)
AS
declare @sqlStr nvarchar(2000)
set @sqlStr= 'UPDATE CD Set '+Cast(@PicType as varchar)+ ' = '+Cast(isnull(@PicName, 'NULL ') as varchar)+ ' Where ID = '+Cast(@ID as varchar)+ ' '
print @sqlStr
EXECUTE sp_executesql @sqlStr
GO
PRINT的结果如下:
UPDATE CD Set Pic_Index = Pic_Index_967.gif Where ID = 967
怎么给Pic_Index_967.gif 加上引号啊??
------解决方案--------------------CREATE PROC CD_UpPic
@ID int,
@PicType varchar(20),
@PicName varchar(200)
AS
declare @sqlStr nvarchar(2000)
set @sqlStr= 'UPDATE CD Set '+Cast(@PicType as varchar)+ ' = ' ' '+Cast(isnull(@PicName, 'NULL ') as varchar)+ ' ' ' Where ID = '+Cast(@ID as varchar)+ ' '
print @sqlStr
EXECUTE sp_executesql @sqlStr
GO