Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to show a value from database:
SQL
rakib = name and SAP = Code

if that name does not have code then i want to show only rakib.
How can i do it using sql server query?

What I have tried:

Nothing
Posted
Updated 10-Sep-18 22:20pm
v2
Comments
CHill60 11-Sep-18 3:33am    
Show the code you tried. Also give us some sample data and the results you expect from that data

1 solution

Try:
SQL
SELECT [Name] + CASE WHEN ISNULL(CODE) THEN '' ELSE '(' + CODE  + ')' END AS [Value] FROM MyTable
 
Share this answer
 
Comments
Skipton Corp 17-Sep-18 12:15pm    
OriginalGriff,
Would you say the following would work same as yours?

SELECT [Name]
,CASE
WHEN [Code] IS NULL
THEN ''
ELSE [Code]
END AS [Value]

FROM MyTable
OriginalGriff 17-Sep-18 13:58pm    
No.

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