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 INTEGER

Author  Topic 

jfm
Posting Yak Master

145 Posts

Posted - 2012-06-06 : 11:29:51
Hi there,

I don't know how to finish this query:

SELECT day_column, SUM(parking_balance) AS parking

SUM(CASE WHEN INT(Personal_balance / 30.5 = 0) THEN parking_balance END) as '0'
FROM My_File
GROUP BY day_column
ORDER BY day_column


The query works without using INT. I really need to do 'Personal_balance/30.5'

Any idea?

Thanks

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-06 : 11:34:46
CASE WHEN convert(INT,Personal_balance / 30.5) = 0 THEN parking_balance END

Only include when Personal_balance / 30.5
I would add
CASE WHEN convert(INT,Personal_balance / 30.5) = 0 THEN parking_balance else 0 END
to avoid the null warning in the sum


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-06-06 : 11:44:58
CASE WHEN Personal_balance < 30.5 THEN parking_balance else 0 END

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

jfm
Posting Yak Master

145 Posts

Posted - 2012-06-06 : 11:49:13
Perfect!

Thanks a lot!
Go to Top of Page
   

- Advertisement -