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 2005 Forums
 Transact-SQL (2005)
 sql help looping through records

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-10-07 : 11:43:45
my current code is


update #temptable
set
startdate = (select min(date) from #temptable tt where tt.name=t.name),
enddate = (select max(date) from #temptable tt ,

where tt.name=t.name)
from #temptable t
delete #temptable where id not in (select max(convert(nvarchar(100),id)) from #temptable group by


what this does is for each name if takes the min and max record and updates start date and end date and then leaves me with just one record - I need to change this instead to order by date and then take for every 2 records -- the first one becomes startdate second enddate (and just save it as 1 record for each 2 with the duration the time between startdate and enddate)

can someone help me with the sql for this please?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-17 : 04:53:42
please post some sample data from table and then explain what you want

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -