Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tsql 指定列名以选择不带临时表的语句结果_Tsql_Select_Alias - Fatal编程技术网

Tsql 指定列名以选择不带临时表的语句结果

Tsql 指定列名以选择不带临时表的语句结果,tsql,select,alias,Tsql,Select,Alias,请看以下代码: 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 'a

请看以下代码:

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]
以这样的方式(伪代码):


只需在第一个select语句中指定列名。例如:

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语句中定义的,除非更改为别名,否则列名将保持这种状态

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