General

turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

10-31-2013
05:34 PM

10-31-2013
05:34 PM

Hi,

I've tried to get the below to work but keep getting erros about '('s in the wrong place etc, I have tried as many variation as I can think of but I think the answer is right in front of me but I can't see it!! - hope someone can help.

Can anyone advise where this code is wrong & how to get it to work?

Thanks

SELECT

CASE

WHEN A.START_DT < '2012-07-31 23:59:59'

AND (A.END_DT > '2012-07-31 23:59:59'

OR A.END_DT IS NULL) THEN '201207',

WHEN A.START_DT < '2012-08-31 23:59:59'

AND (A.END_DT > '2012-08-31 23:59:59'

OR A.END_DT IS NULL) THEN '201208'

END AS Month_Id,

From Table_A

1 REPLY

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

10-31-2013
05:47 PM

10-31-2013
05:47 PM

Got it !!

No comma between the clauses ...

CASE

WHEN A.START_DT < '2012-07-31 23:59:59'

AND (A.END_DT > '2012-07-31 23:59:59'

OR A.END_DT IS NULL) THEN '201207'

WHEN A.START_DT < '2012-08-31 23:59:59'

AND (A.END_DT > '2012-08-31 23:59:59'

OR A.END_DT IS NULL) THEN '201208'

END AS Month_Id

From Table_A