之前创建了一个临时表##temp2,得到的结果如下: ID 字段名 数据类型
1 1 ID int
2 2 Name char
3 3 Password char
declare @oo char(10)
/*取出该表的字段的数量*/
set @oo=(select count(name) as 字段数量 from syscolumns where id=object_id(aa))
declare @i int
set @i = 1
while @i <= @oo
begin
declare @(select 字段名 from ##temp2 where [ID]=''+@i+'') (select 数据类型 from ##temp2 where [ID]=''+@i+'')
set @i = @i + 1
end
我现在想在这次循环里,让它根据临时表##temp2中的字段自动声明变量,想得到的结果如下:declare @ID int
declare @Name char
declare @Password char但是一运行就会出现 “'(' 附近有语法错误。” 谁知道应该如何修改?请高手给予明确答复,谢谢了!!
在线等,急~!~~如有结果立马结贴并给分~~~~~!!!!~~~
1 1 ID int
2 2 Name char
3 3 Password char
declare @oo char(10)
/*取出该表的字段的数量*/
set @oo=(select count(name) as 字段数量 from syscolumns where id=object_id(aa))
declare @i int
set @i = 1
while @i <= @oo
begin
declare @(select 字段名 from ##temp2 where [ID]=''+@i+'') (select 数据类型 from ##temp2 where [ID]=''+@i+'')
set @i = @i + 1
end
我现在想在这次循环里,让它根据临时表##temp2中的字段自动声明变量,想得到的结果如下:declare @ID int
declare @Name char
declare @Password char但是一运行就会出现 “'(' 附近有语法错误。” 谁知道应该如何修改?请高手给予明确答复,谢谢了!!
在线等,急~!~~如有结果立马结贴并给分~~~~~!!!!~~~
来使用,不能定义动态的变量的
动态变量,得搭配在动态SQL中使用