注册 登录
编程论坛 SQL Server论坛

存储过程中怎样给变量赋包含查询条件的查询出的值的问题

wyl918 发布于 2007-08-18 11:08, 1013 次点击

declare @StartID int
declare @strWhere nvarchar(1000)

set @strWhere='id=2'
select @StartID=ID from gwlz_gw_table g where id=2
select @StartID
select @strWhere

我想把代码中的 id=2 换成 @strWhere 该怎么弄啊
我的最终目的是把查询出的编号赋给 @StartID 这个变量

2 回复
#2
shulei5215212007-08-19 07:19
条件 where id=@id
#3
Kendy1234562007-08-20 10:57
declare @sql varchar(1000)

set @sql = 'select @StartID=ID from gwlz_gw_table g where ' + @strWhere

exec (@sql)
1