Solved

How to create a select statement with a conditional

Posted on 2008-06-18
3
193 Views
Last Modified: 2010-03-20
I have the following sql:
select sum(qty * unit_cost) from table1 where id=@id

I need to revise this such that if the qty value is -1, I want to make it 1 and then multiply unit_cost

Can anyone help?
Thx,
ipaman
0
Comment
Question by:ipaman
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
nexusnation earned 50 total points
ID: 21816283
What DB are you using?

If you are using Access, you can do:

elect sum(Abs(qty) * unit_cost) from table1 where id=@id

Assuming that qty will always be >= -1.
0
 

Author Comment

by:ipaman
ID: 21816304
i am using SQL Server 2005
0
 
LVL 12

Expert Comment

by:nexusnation
ID: 21816666
Did it work?  I'm not sure it SQL Server 2005 has that function.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question