Solved

How to create a select statement with a conditional

Posted on 2008-06-18
3
192 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query 26 68
sql server computed columns 11 34
how to double quote a string for an inline sql statement. 8 73
MYSQL responding very slow 3 23
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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