Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 9th, 2009, 08:37 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Question Compare one field agaist two fields


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

Last edited by snufse; April 9th, 2009 at 09:01 AM..
 
Old April 13th, 2009, 01:45 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

Snufse:
You did not state what you want to do with the comparisons of Table 1 and Table 2. Are you wanting to identify the costcenters of Table 2 that are without the CostCodeType? or what?

My response is based on Table1 and Table2 only and performed outside of your listed code.

PASS1: Build a QUERY of Table 2 that combines the CostCenters and CostCenterType. Save NewTable2.

PASS2: Build a QUERY of Table 1 that extracts only one occurence of CostCenter. This could be a little tricky and you may have to include region or location code, but that is up to you and your application. This response is thinking the CostCenter is enough. To build a new Table1 use: SELECT DISTINCT CostCenter. SaveAs NewTable1

PASS3: This PASS is the Comparison of NewTable1 and NewTable2, which you save as CompareCostTbl. Use the LEFT JOIN in the SELECT Statement. This will compare the two tables and will produce or list every entry or value in NewTable1 and Matches and Nomatches of NewTable2. The NoMatches will be "Blank" and all saved in the CompareCostTbl.

PASS4: This Pass is left up to you as what you want to do with either the CostCenter Matches of CostCenter Non-Matches or both.

However, I strongly suggest and recommend NOT to do the above in one Pass, it can really "hang" the system.

Hope this Helps.
__________________
Disclaimer: The above comments are solely the opinion of one person and not to be construed as a directive or an incentive to commit fraudulent acts.





Similar Threads
Thread Thread Starter Forum Replies Last Post
string compare in table field alxtech SQL Server 2000 1 April 27th, 2007 12:25 AM
Compare two fields from different tables pallone SQL Server 2000 10 March 23rd, 2007 05:14 PM
compare form field to database before submit chelle60 Javascript How-To 3 January 2nd, 2007 05:42 AM
compare these date fields and compare and get the susanring Oracle 1 July 24th, 2006 04:58 PM
Compare only the date portion of a datetime field CricketMaster Access 6 April 27th, 2005 01:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.