Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to show a column [Id] with auto increment with respect select statement.
Something like that.
Values of Field Column [Value] is creating by Case statement

Id   Value
1    Created
2    removed
3    N/A


What I have tried:

SELECT DISTINCT 1 AS StId, 
CASE WHEN SD.Id = 0 THEN 'N/A' ELSE
CASE WHEN  SD.Id != 0 THEN 'Created' ELSE 'Removed' END END AS DisplayValue
FROM Student SD

Its Showing Recode looking like that
Id	Value
1	Created
1	Removed
1	N/A
Posted
Updated 29-Jul-19 20:12pm

1 solution

Use a Join: Set up a second table:
DisplayValues
ID     INT, IDENTITY
Desc   NVARCHAR(MAX)
And populate it with your text strings.
Then it's simple:
SQL
SELECT s.ID, d.Desc
FROM Students s
JOIN DisplayValues d ON s.ID = d.ID
 
Share this answer
 
Comments
Maciej Los 30-Jul-19 15:31pm    
Does Desc shouldn't be around with brackets?
OriginalGriff 30-Jul-19 15:38pm    
Probably - I'm on tablet ATM, so SQL is a PITA; that was early in the morning ... :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900