Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

create sql str with special condition Expand / Collapse
Author
Message
Posted Friday, March 22, 2013 11:02 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, May 15, 2013 3:11 AM
Points: 12, Visits: 55
create sql str with special condition
hellow
I have 2 table
Table a(code, price, check)
Table b(code, percent)
I want to create a sql string such below:
Select a.code, a.price, (price * percent) as new_field
From a,b
Where a.code = b.code

And this condition must be consider in sql str:
If (check = 1)
{
New_field = price * percent
}
Else
{
New_field = price * percent * 8
}

Now how can put above condition in sql str?
Thanks very much

Post #1434406
Posted Tuesday, March 26, 2013 12:23 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, September 25, 2014 10:56 PM
Points: 1,349, Visits: 475
Select a.code, a.price, (price * percent * case when check = 1 then 1 else 8 end) as new_field
From a,b
Where a.code = b.code

?
Post #1435275
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse