看看这段代码:
DECLARE @bufferOrder INT = 1, @capacityOrder INT = 2, @priceOrder INT = 3, @angleSpeedOrder INT = 4
SELECT 'buffer', @bufferOrder
UNION
SELECT 'capacity', @capacityOrder
UNION
SELECT 'price', @priceOrder
UNION
SELECT 'angle_speed', @angleSpeedOrder
我可以在不使用临时表的情况下分配两个列名吗?
[INSERT INTO @#tempTabel (columnName1,columnName2) + above code]
像这样(伪代码):
above code +
AS columnName1,columnName2
答案 0 :(得分:2)
只需在第一个select语句中指定列名。 EG:
declare @int int = 1, @int2 int = 2, @int3 int = 3, @int4 int = 4;
select 'thing 1' as thing, @int as integer
union
select 'thing 2', @int2
union
select 'thing 3', @int3
我可以轻松地为此添加更多内容和更多内容。列名在第一个select语句中定义,并保持不变,除非它们是更改的别名。