Solved

How to create a select statement with a conditional

Posted on 2008-06-18
3
183 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
Comment Utility
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
Comment Utility
i am using SQL Server 2005
0
 
LVL 12

Expert Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now