Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to add two database fields together if result is zero 1

Status
Not open for further replies.

ITmfgCO

IS-IT--Management
Sep 14, 2006
25
US
I am createing a database view and need to have a case statement when the Unit Price field is equal to zero, I want to add the material cost and burden cost and return it to the unit price field.

esetially, IIf([dbo_CUST_order_line.unit_price]=0,[dbo_Part.UNIT_MATERIAL_COST]+[dbo_Part.UNIT_BURDEN_COST],[dbo_CUST_order_line.unit_price]) AS price

however I can not get this to work in SQL Qery Analyser....
 
There is no IIF() function in TSQL
Code:
esetially, 
 CASE WHEN [dbo_CUST_order_line.unit_price]=0
      THEN [dbo_Part.UNIT_MATERIAL_COST]+
           [dbo_Part.UNIT_BURDEN_COST]
 ELSE [dbo_CUST_order_line.unit_price] END AS price

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Awesome, that worked great!

thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top