Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Problems With A SELECT Statement

Author  Topic 

BRKWA
Starting Member

1 Post

Posted - 2005-10-31 : 12:19:54
I'm sure that this is a fairly easy statement but it exceeds my ability in SQL. What I am trying to do is double pull from one table. I am trying to build an aging report for my accounts payable dept. The table has some of the worst organization i've ever seen. I need to pull all records from the table with voucher type "V", and then pull all records with voucher type "C" or "X" but have them take the date of the records with voucher type "V" that share the same invoice #. Does this make any sense? I thought I knew how to do this but i've only managed to give myself a headache every time i come back to this point. Any help would be greatly appreciated.

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-10-31 : 12:43:05
please read this http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx and provide the requested info. thanks.



-ec
Go to Top of Page

mriverol
Starting Member

10 Posts

Posted - 2005-11-01 : 08:23:02
Hi, if i am understanding your issue correctly the following should work

Test Table format and data

voucher invoice dt

V 1 2005-01-01 00:00:00
V 2 2005-01-09 00:00:00
V 3 2005-01-15 00:00:00
V 4 2005-01-19 00:00:00
C 1
C 2
C 3
C 4
X 1
X 2
X 3
X 4


Query:

update not_v
set dt = v.dt
from tbl v
inner join tbl not_v on v.invoice = not_v.invoice
and v.voucher = 'v'
and not_v.voucher in ('c', 'x')

Martin.
Go to Top of Page
   

- Advertisement -