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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to use case statement ?

Author  Topic 

jylland
Starting Member

27 Posts

Posted - 2012-12-05 : 12:56:52
hi I have problem

SELECT SUM(value) AS Totalos

then I want validation of the Total

If Totalos > 0
then 0
else (totalos-100) end AS Price

FROM dbo.database
where......

But how do I do this with a case statement ?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-12-05 : 13:05:15
[code]SELECT
CASE WHEN Totalos > 0 THEN 0 ELSE (totalos-100) END AS Price
FROM
dbo.database[/code]BTW, "database" is not really a good name for a table. If you do choose to use it, use it like dbo.[database]
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-05 : 13:08:45
quote:
Originally posted by jylland

hi I have problem

SELECT SUM(value) AS Totalos from tabel where ....

then I want validation of the Total

If Totalos > 0
then 0
else (totalos-100) end AS Price

FROM dbo.database
where......

But how do I do this with a case statement ?



Case When SUM(Values) > 0 then 0 Else SUM(Values)- 100 End
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-12-05 : 13:10:21
What sodeep said. I didn't read the question properly.
Go to Top of Page

jylland
Starting Member

27 Posts

Posted - 2012-12-05 : 18:38:21
quote:
Originally posted by sunitabeck

SELECT
CASE WHEN Totalos > 0 THEN 0 ELSE (totalos-100) END AS Price
FROM
dbo.database
BTW, "database" is not really a good name for a table. If you do choose to use it, use it like dbo.[database]



Great thanks
Go to Top of Page

jylland
Starting Member

27 Posts

Posted - 2012-12-05 : 18:40:13
quote:
Originally posted by sodeep

quote:
Originally posted by jylland

hi I have problem

SELECT SUM(value) AS Totalos from tabel where ....

then I want validation of the Total

If Totalos > 0
then 0
else (totalos-100) end AS Price

FROM dbo.database
where......

But how do I do this with a case statement ?



Case When SUM(Values) > 0 then 0 Else SUM(Values)- 100 End


Thanks very much great



Thanks very much great
Go to Top of Page
   

- Advertisement -