Solved

How to create a select statement with a conditional

Posted on 2008-06-18
3
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Title # Comments Views Activity
sql query display the latest row 10 62
T-SQL: Stored Procedure Syntax 3 40
Creating a View from a CTE 15 41
Access Query To Find The Average Date Between Two Dates 3 14
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
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…
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…

738 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