SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to use case statement ?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jylland
Starting Member

27 Posts

Posted - 12/05/2012 :  12:56:52  Show Profile  Reply with Quote
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 ?

Edited by - jylland on 12/05/2012 17:16:18

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/05/2012 :  13:05:15  Show Profile  Reply with Quote
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]
Go to Top of Page

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/05/2012 :  13:08:45  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

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

jylland
Starting Member

27 Posts

Posted - 12/05/2012 :  18:38:21  Show Profile  Reply with Quote
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 - 12/05/2012 :  18:40:13  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000