[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • 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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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