-- 示例数据
CREATE TABLE tb(a1 int, a2 int, a3 int)
INSERT tb SELECT 1, 2, 3
GO-- 处理
SELECT b1 = 'a1', b2 = a1 FROM tb
UNION ALL
SELECT b1 = 'a2', b2 = a2 FROM tb
UNION ALL
SELECT b1 = 'a3', b2 = a3 FROM tb
GODROP TABLE tb-- 结果
b1 b2
---- -----------
a1 1
a2 2
a3 3(3 行受影响)
CREATE TABLE tb(a1 int, a2 int, a3 int)
INSERT tb SELECT 1, 2, 3
GO-- 处理
SELECT b1 = 'a1', b2 = a1 FROM tb
UNION ALL
SELECT b1 = 'a2', b2 = a2 FROM tb
UNION ALL
SELECT b1 = 'a3', b2 = a3 FROM tb
GODROP TABLE tb-- 结果
b1 b2
---- -----------
a1 1
a2 2
a3 3(3 行受影响)
set @s='select b1= '
select @s=@s+''''+name+''',b2='+name+' from tb
union all
select b1=' from (select c.name from sysobjects o
inner join syscolumns c on o.id=c.id where o.name='tb')a
select @s=substring(@s,1,len(@s)-len(right(@s,22)))
exec (@s)
open jcsltx
declare @name varchar(100)
fetch next from jcsltx into @name
while @@fetch_status = 0
begin
insert into t1(B1,B2)
SELECT B1=+ @name + , B2 =@name FROM tb'//B1的值应该怎么写
fetch next from jcsltx into @name
end
close jcsltx
deallocate jcsltx
这是最后根据zjcxc(邹建)的提示写的,但是B1的值还是不会写。请zjcxc(邹建)帮忙