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: Monday, October 6, 2014 5:22 AM
Points: 13, Visits: 70
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: Today @ 6:49 AM
Points: 1,356, Visits: 478
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