日期:2014-05-17 浏览次数:20513 次
CREATE proc sp_xs
@JGBZ nVARCHAR(50),
@column1 nVARCHAR(50)
as
declare @sel nvarchar(500)
set @sel = 'select '+ @column1+' from 刻蚀 where 加工步骤='''+ @JGBZ +''''
EXEC (@sel)
alter proc sp_xs
@JGBZ NVARCHAR(50),
@column1 nVARCHAR(50)
as
declare @sel nvarchar(500)
SET @sel = N'select ' + @column1 + ' from 刻蚀 where 加工步骤=@JGBZ' --#2.字段名,表名,无法用传参的方式动态。想动态只能拼SQL
exec sp_executesql @sel, N'@JGBZ NVARCHAR(50)', @JGBZ --#1.缺少后面两个参数
GO
EXEC sp_xs 'P+ET','SRJY'
GO
CREATE proc sp_xs1
@JGBZ nVARCHAR(50),
@column1 nVARCHAR(50)
as
declare @sel nvarchar(500)
set @sel = 'select '+ @column1+' from 刻蚀 where 加工步骤='''+ @JGBZ +'''' --这儿少了'号
--PRINT @sel
Exec(@sel)
GO
EXEC sp_xs1 'P+ET','SRJY'
GO