Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this very weird need, I have a query that contains some conditions. Here is a sample one.

SELECT FirstName, LastName, ConditionalColumn FROM Employee
WHERE LastName != 'Ciaz'

I want to show the WHERE conditional column value in ConditionalColumn. So that column will have Ciaz in it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
222 views
Welcome To Ask or Share your Answers For Others

1 Answer

Declare @Param Varchar(MAX) = 'Ciaz'
SELECT FirstName, LastName, @Param AS ConditionalColumn FROM Employee
WHERE LastName != @Param

Line 1: Declare a Varchar (string) variable @Param and assign value of 'Ciaz'. Line 2: In Select query with FirstName, LastName add @Param with 'As' keywords and column name 'ConditionalColumn', with this @Param shown as a column in your query.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...