Results 1 to 4 of 4

Thread: Compare one field against two fields

  1. #1
    Join Date
    Mar 2009
    Posts
    32

    Smile [Resolved] Compare one field against 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; 04-20-2009 at 06:54 AM.

  2. #2
    Join Date
    Feb 2009
    Posts
    17
    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

  3. #3
    Join Date
    Apr 2009
    Posts
    3
    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.

  4. #4
    Join Date
    Mar 2009
    Posts
    32
    Thank you. Got it working now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •