SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to convert Multiple Records in to CSV
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

praveen050
Starting Member

9 Posts

Posted - 05/23/2012 :  03:00:40  Show Profile  Reply with Quote
Write a SQL to convert Multiple Records in to Comma Separated values and Insert into Different table
Write a sql to load data as comma separated one record per Agent in to T_AGENT_CSVEXT.
EX: if TAGENT has
Agent_ID Agent_Extension
aapena 83601014
aapena 83601014
aapena 83605027
aapena 83605236
aapena 83605473
aapena 83605724

T_AGENT_CSVEXT should have
Agent_ID Agent_Extension
aapena 83601014,83605027,83605236,83605473,83605724


Edited by - praveen050 on 05/23/2012 03:44:58

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 05/23/2012 :  03:12:11  Show Profile  Reply with Quote
Thank you for posting your assignment question.

Can you also shared with us the solution ?


KH
Time is always against us

Go to Top of Page

praveen050
Starting Member

9 Posts

Posted - 05/23/2012 :  03:14:14  Show Profile  Reply with Quote
i m not getting the solution
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 05/23/2012 :  03:57:03  Show Profile  Reply with Quote
what have you tried ?


KH
Time is always against us

Go to Top of Page

praveen050
Starting Member

9 Posts

Posted - 05/23/2012 :  09:04:02  Show Profile  Reply with Quote
open tabcur
declare @g varchar(1000)
fetch tabcur into @g
while (@@FETCH_STATUS=0)
begin
if (@g=@g)

DECLARE @ext varchar(100)
SELECT @ext = COALESCE(@ext + ', ', '') + cast(id as varchar) FROM tab where mm=@g
print @g +' ' +@ext

fetch tabcur into @g
end

and my result

hh 1, 2, 3, 4
hh 1, 2, 3, 4, 1, 2, 3, 4
hh 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4
hh 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4
gg 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 7
gg 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 7, 5, 6, 7
gg 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 7, 5, 6, 7, 5, 6, 7

but i want
hh 1,2,3,4
gg 5,6,7
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 05/23/2012 :  09:24:22  Show Profile  Reply with Quote
refer to this thread http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254
and use the for xml path method shown there


KH
Time is always against us

Go to Top of Page

praveen050
Starting Member

9 Posts

Posted - 05/24/2012 :  02:14:14  Show Profile  Reply with Quote
Thanks for your suggestion i got the answer, actually i have table with more than 8000 rows
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 05/24/2012 :  02:47:02  Show Profile  Reply with Quote
quote:
Originally posted by praveen050

Thanks for your suggestion i got the answer, actually i have table with more than 8000 rows


that will not be an issue.

Just use the SELECT query in that thread


KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000