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)
 i need to avoid cursor

Author  Topic 

viniit24
Starting Member

3 Posts

Posted - 2007-11-01 : 05:41:55
i have a table called Trustee with fields TrustNumber,ClientID and TrustName. here corresponding to a TrustNumber there could be more than one records. My requirement is to transfer all the rows corresponding to each distinct TrustNumber in a single row in a new table with fields say TrustNumber,ClientID1,TrustName2,ClientID2,TrustName2, ClientID3,TrustName3, and so on, maximum to 7. i had solved the problem using two cursors, but that is very time consuming( it took almost an hour to processed 58k records).
Can anyone suggest a better option for this.

thanks,
vineet

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-01 : 05:51:09
can you post your table DDL ? same sample records from that table and the required result from that sample ?

Also please state the version of Microsoft SQL Server that you are using.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

viniit24
Starting Member

3 Posts

Posted - 2007-11-01 : 06:50:55
Trustee table:
Trust Number ClientID TrustName
040312-06 11154 Gilbert and Clemille Lai Trust
040312-06 11155 Howard and Gladys Tengan Trust
040312-06 11156 Tsutomu and Frances Abe Living Trust

Destination Table's fields( single row):
040312-06 11154 Gilbert and Clemille Lai Trust 11155 Howard and Gladys Tengan Trust 11156 Tsutomu and Frances Abe Living Trust NULL NULL NULL NULL NULL NULL NULL NULL

i m using sql server 2005 version,
data type:
Trust Number varchar(50)
all trust name fields varchar(50)
All Client ID fields int

thanks,
vineet
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2007-11-01 : 07:55:55
(Moved to the SQL Server 2005 T-SQL forum.)

=================================================
Creating tomorrow's legacy systems today. One crisis at a time.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-01 : 08:17:57
Refer
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -