• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 460
  • Last Modified:

if then else

Hi.
How can i do this in sql
IF NUM IS NULL THEN
IF TYP_CDE ='ABC'
THEN NUM ='001'
ELSE 'Unknown'

Thanks
0
sam2929
Asked:
sam2929
1 Solution
 
VonCaliCommented:
I would probably use nested Case statements:
SELECT
	CASE
		WHEN NUM IS NULL
			CASE TYP_CDE 
				WHEN 'ABC' THEN '001'
				ELSE 'Unknown'
			END
		ELSE NUM
	END AS NUM
FROM TableName

Open in new window

0
 
25112Commented:
SELECT
CASE WHEN NUM IS NULL AND TYP_CDE ='ABC' THEN '001' ELSE 'Unknown' END COLUMN1
FROM TABLE
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now