# Database Discussions > Microsoft SQL Server 2005 >  Compare one field against two fields

## snufse

I have a query where I need to compare 1 field against value of 2 fields.

update #Combined_LaborTable 
set    jdesumhrs = #JDE_LaborTable.jde_sum_hrs, 
       differencehrs = (eqsumhrs - #JDE_LaborTable.jde_sum_hrs),
       unitofmeasure = #JDE_LaborTable.jde_uom
from   #Combined_LaborTable, #JDE_LaborTable
where  #Combined_LaborTable.costcode = #JDE_LaborTable.jde_cost_code + JDE_LaborTable.jde_cost_type

costcode value: 01004-AV

jde_cost_code value: 01004 and jde_cost_type value AV

Sometimes there are no value in jde_cost_type, then need to compare only the costcode and jde_cost_code

Thank you

----------


## tattooedscorpdc

You can go about this a couple of ways, one complex SQL query joining the fields or two simple ones with conditional statements testing the values of each individual field and the action that is required depending on the value of the field being compared.,

Is this wahtyou wer elooking for?  the challenge isn't very clear in your post.

Hope this helps,

Larry Darrah
MS Architect Evangelist

----------


## MikeH

Presuming:
" #JDE_LaborTable.jde_cost_code + JDE_LaborTable.jde_cost_type "
is a concattenation not an arithmetic operation.
And:
"#Combined_LaborTable.costcode "
contains both the cost_code '01004' and the
cost_type 'AV' 
separated by a '-' dash.

You should consider the type and length (fixed, variable) of the three fields when concattenating two columns to compare with the third. 
You may want to consider Trim and Strip functions if available in your RDBMS.

----------


## snufse

Thank you. Got it working now.

----------

