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
 General SQL Server Forums
 New to SQL Server Programming
 comma separated value code error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

learning_grsql
Posting Yak Master

218 Posts

Posted - 06/21/2013 :  06:22:03  Show Profile  Reply with Quote
I get error "incorrect syntax near for" for the below code. Can you please let me know where the incorrect syntax is?




stuff(
(select ',' + t.column_name as column_name from
(
select column_name as column_name  from information_schema.columns
where table_name = 'ate1') as t
for XML PATH ('')),1,1,'') as column

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/21/2013 :  06:28:49  Show Profile  Reply with Quote

..
stuff((select ',' + t.column_name  from information_schema.columns
where table_name = 'ate1' for XML PATH ('')),1,1,'') as column
..


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

learning_grsql
Posting Yak Master

218 Posts

Posted - 06/21/2013 :  06:35:39  Show Profile  Reply with Quote
Thanks Visakh16 however I get the same error for your code also "incorrect syntax near for"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/21/2013 :  06:43:07  Show Profile  Reply with Quote
show your full code please


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2168 Posts

Posted - 06/21/2013 :  06:45:04  Show Profile  Reply with Quote
SELECT 
stuff(
(select ',' + column_name 
	from information_schema.columns
	where table_name = 'ate1'
	for XML PATH ('')),1,1,'') as ColumnNames



--
Chandu
Go to Top of Page

learning_grsql
Posting Yak Master

218 Posts

Posted - 06/21/2013 :  07:31:24  Show Profile  Reply with Quote
Thanks Bandi, it's working now.
@Visakh16, it seems I missed to put "select" in the front. I started my code with stuff....... :)
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2168 Posts

Posted - 06/21/2013 :  07:37:51  Show Profile  Reply with Quote
quote:
Originally posted by learning_grsql

Thanks Bandi, it's working now.


welcome

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/21/2013 :  08:53:56  Show Profile  Reply with Quote
quote:
Originally posted by learning_grsql

Thanks Bandi, it's working now.
@Visakh16, it seems I missed to put "select" in the front. I started my code with stuff....... :)


ah.. i thought you just posted the problem part

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.11 seconds. Powered By: Snitz Forums 2000