I have a SQL Server 2008 table called invoices. I’m trying to use an UPDATE SQL command to perform the following column compares within a single invoice table. Example below. Tried numerous attempts, but do not get the results as expected in the offset column. Any help would be much appreciated – thanks Jeff.
Challenge 1:
UPDATE the below invoice table to identify the offsetting credits and SET offset=’x’ WHERE:
Vendor number is equal
Invoice number is equal
Invoice amount is equal
Debit credit code is not equal
Vendor Invoice Invoice invoice debit offset
Number Number date amount credit
123 1 1/10/08 $50.00 D
123 2 1/10/08 $10.00 D X
123 3 1/10/08 $30.00 D
123 2 1/10/08 $10.00 C X
33 IN1 2/1/08 $5.00 D
33 IN3 1/1/08 $4.00 D X
33 IN3 1/1/08 $4.00 C X
33 IN3 1/1/08 $4.00 D
33 IN2 6/5/08 $1.00 D
Challenge 2:
UPDATE the below invoice table to identify the offsetting credits and SET offset=’x’ WHERE:
Vendor number is equal
Invoice number is equal
Invoice amount is equal after *-1
Vendor Invoice Invoice invoice offset
Number Number date amount
123 1 1/10/08 $50.00
123 2 1/10/08 $10.00 X
123 3 1/10/08 $30.00
123 2 1/10/08 $-10.00 X
33 IN1 2/1/08 $5.00
33 IN3 1/1/08 $4.00 X
33 IN3 1/1/08 $-4.00 X
33 IN3 1/1/08 $4.00
33 IN2 6/5/08 $1.00
Challenge 1:
UPDATE the below invoice table to identify the offsetting credits and SET offset=’x’ WHERE:
Vendor number is equal
Invoice number is equal
Invoice amount is equal
Debit credit code is not equal
Vendor Invoice Invoice invoice debit offset
Number Number date amount credit
123 1 1/10/08 $50.00 D
123 2 1/10/08 $10.00 D X
123 3 1/10/08 $30.00 D
123 2 1/10/08 $10.00 C X
33 IN1 2/1/08 $5.00 D
33 IN3 1/1/08 $4.00 D X
33 IN3 1/1/08 $4.00 C X
33 IN3 1/1/08 $4.00 D
33 IN2 6/5/08 $1.00 D
Challenge 2:
UPDATE the below invoice table to identify the offsetting credits and SET offset=’x’ WHERE:
Vendor number is equal
Invoice number is equal
Invoice amount is equal after *-1
Vendor Invoice Invoice invoice offset
Number Number date amount
123 1 1/10/08 $50.00
123 2 1/10/08 $10.00 X
123 3 1/10/08 $30.00
123 2 1/10/08 $-10.00 X
33 IN1 2/1/08 $5.00
33 IN3 1/1/08 $4.00 X
33 IN3 1/1/08 $-4.00 X
33 IN3 1/1/08 $4.00
33 IN2 6/5/08 $1.00
Comment