这是我的简单查询。如何在sql server中为此查询分配列标题/名称?
Declare @custName INT
Set @custName = 2
Select case @custName
when 1 then 'abc'
when 2 then 'xyz'
when 3 then 'pqr'
end
以上查询运行良好。
输出是
我想指定的列或标题名称作为客户名称。
我试着查询的一些排列组合。
Declare @custName INT Set @custName = 2 Select case @custName as CustomerName when 1 then 'abc' when 2 then 'xyz' when 3 then 'pqr' end
Declare @custName INT Set @custName = 2 Select CustomerName as case @custName when 1 then 'abc' when 2 then 'xyz' when 3 then 'pqr' end
但返回错误。
所以我的问题是如何分配一些适当的标题/列名称?
谢谢:)。这种方式由@Abdul发布,如果你发布其他两种方式,这将是非常好的。 –
Yeah.Great。(Y):) –