Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 CASE WHEN

Author  Topic 

jfm
Posting Yak Master

145 Posts

Posted - 2012-05-23 : 04:29:45
Hi there,

I made the following query, but I have:

msg 156, level 15, state 1, line 2
incorrect syntax near the keyword "case"

USE my_database
CASE WHEN Column_E < Column_D THEN 0
ALTER TABLE my_table
ADD Column_Z AS (DATEDIFF(DAY, Column_A, Column_E))

How can I solve the problem?

Thanks

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2012-05-23 : 05:01:26
[code]
USE my_database
ALTER TABLE my_table
ADD Column_Z AS (CASE WHEN Column_E < Column_D THEN 0 ELSE DATEDIFF(DAY, Column_A, Column_E) END)
[/code]

- Lumbago
My blog-> http://thefirstsql.com
Go to Top of Page

jfm
Posting Yak Master

145 Posts

Posted - 2012-05-23 : 10:05:48
Perfect!

Thanks a lot!

quote:
Originally posted by Lumbago


USE my_database
ALTER TABLE my_table
ADD Column_Z AS (CASE WHEN Column_E < Column_D THEN 0 ELSE DATEDIFF(DAY, Column_A, Column_E) END)


- Lumbago
My blog-> http://thefirstsql.com

Go to Top of Page
   

- Advertisement -