473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Syntax, please :-((((((((((((((

Hi. I'm trying to build a query which would return TRUE or FALSE as
'IsRerun' depending on the matching status with another table, as
follows (simplified query):

SELECT ImportedPINS.PIN,
CASE ManagerReport.PIN
WHEN (IS NULL)
THEN 'FALSE'
ELSE
'TRUE'
END AS IsRerun,
FROM
ImportedPINS LEFT OUTER JOIN ManagerReport
ON ImportedPINS.PIN = ManagerReport.PIN

This version returns "Incorrect syntax near the keyword 'IS'"

I have tried a lot of versions..... like
CASE ManagerReport.PIN
WHEN ManagerReport.PIN IS NULL
THEN 'TRUE'
ELSE
'FALSE'
END AS IsRerun

or

CASE ManagerReport.PIN
WHEN IS NULL
THEN 'TRUE'
ELSE
'FALSE'
END AS IsRerun

or

CASE ManagerReport.PIN
WHEN NULL
THEN 'TRUE'
ELSE
'FALSE'
END AS IsRerun

(this one executes, but ALL show as TRUE, and my data says that out of
200 test records I should have 195 Reruns and 5 Not Reruns)

Please, how should I write this ?
Thanks a lot
Alex.

Feb 15 '07 #1
3 1860
It's quite simple... once you've seen it!

SELECT CASE WHEN ManagerReport.PIN IS NULL THEN 'TRUE'
ELSE 'FALSE' END AS IsRerun
FROM ...

HTH,
Gert-Jan
Radu wrote:
>
Hi. I'm trying to build a query which would return TRUE or FALSE as
'IsRerun' depending on the matching status with another table, as
follows (simplified query):

SELECT ImportedPINS.PIN,
CASE ManagerReport.PIN
WHEN (IS NULL)
THEN 'FALSE'
ELSE
'TRUE'
END AS IsRerun,
FROM
ImportedPINS LEFT OUTER JOIN ManagerReport
ON ImportedPINS.PIN = ManagerReport.PIN

This version returns "Incorrect syntax near the keyword 'IS'"

I have tried a lot of versions..... like
CASE ManagerReport.PIN
WHEN ManagerReport.PIN IS NULL
THEN 'TRUE'
ELSE
'FALSE'
END AS IsRerun

or

CASE ManagerReport.PIN
WHEN IS NULL
THEN 'TRUE'
ELSE
'FALSE'
END AS IsRerun

or

CASE ManagerReport.PIN
WHEN NULL
THEN 'TRUE'
ELSE
'FALSE'
END AS IsRerun

(this one executes, but ALL show as TRUE, and my data says that out of
200 test records I should have 195 Reruns and 5 Not Reruns)

Please, how should I write this ?
Thanks a lot
Alex.
Feb 15 '07 #2
Radu (cu*************@yahoo.com) writes:
SELECT ImportedPINS.PIN,
CASE ManagerReport.PIN
WHEN (IS NULL)
THEN 'FALSE'
ELSE
'TRUE'
END AS IsRerun,
FROM
ImportedPINS LEFT OUTER JOIN ManagerReport
ON ImportedPINS.PIN = ManagerReport.PIN

This version returns "Incorrect syntax near the keyword 'IS'"
The CASE expressions has two forms. The main form is

CASE WHEN expression1 THEN expression2 WHEN expression2 THEN ....

The other form is

CASE expresion1 WHEN expression2 THEN expression3 WHEN expression4...

This is a shortcut for

CASE WHEN expr1 = expr2 THEN expr3 WHEN expr1 = expr4 THEN ...

Thus, in your case:

CASE WHEN ManagerReport.PIN IS NULL
THEN 'TRUE'
ELSE
'FALSE'
END AS IsRerun
CASE ManagerReport.PIN
WHEN NULL
THEN 'TRUE'
ELSE
'FALSE'
END AS IsRerun

(this one executes, but ALL show as TRUE, and my data says that out of
200 test records I should have 195 Reruns and 5 Not Reruns)
This is because all comparisons with NULL yields UNKNOWN, as NULL is
an unknown value.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Feb 15 '07 #3
Thank you both, Gert-Jan and Erland, for your reading & answering my
post.

Alex. :-)))

Feb 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.