Solved

How to create a select statement with a conditional

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

615 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