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
 General SQL Server Forums
 New to SQL Server Programming
 Join Query

Author  Topic 

sanjay5219
Posting Yak Master

240 Posts

Posted - 2008-08-12 : 09:07:57
Dear All,
I have one table with below column
Customer Id : Travel Date
C1-01Aug 2008
C2-02Aug 2008
C1-03Aug 2008
C1-04Aug 2008
No i have to update another table with these columsn
Customer Id : Travel Date : Next Travel Date it should look like this
C1:01Aug 2008:03Aug 2008
C1:03Aug 2008:04Aug 2008
C2:02Aug2008:NULL

please tell me solution


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-12 : 09:43:47
Are you using sql 2005?
Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 2008-08-12 : 09:45:12
Sql 2000
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-12 : 09:48:50
[code]SELECT (SELECT COUNT(*) FROM YourTable WHERE CustomerId=t.CustomerId AND TravelDate < t.TravelDate) + 1 AS Seq,
* INTO #Temp
FROM YourTable t

INSERT INTO Table2
SELECT t1.CustomerID,t1.TravelDate,t2.TravelDate
FROM #Temp t1
LEFT JOIN #Temp t2
ON t1.CustomerID=t2.Customer_ID
AND t2.Seq=t1.Seq+1[/code]
Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 2008-08-12 : 10:01:40
I have one doubt I have two table T1 table from where i have to extarct the date and table T2 where i have to update Next Travel Date.

Which table will come in first query <YourTable>
Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 2008-08-12 : 12:14:38
No it is not solving my problem
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-12 : 12:18:52
quote:
Originally posted by sanjay5219

No it is not solving my problem


Why?what was error?
Go to Top of Page
   

- Advertisement -