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
 comma separated value code error

Author  Topic 

learning_grsql
Posting Yak Master

230 Posts

Posted - 2013-06-21 : 06:22:03
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

52326 Posts

Posted - 2013-06-21 : 06:28:49
[code]
..
stuff((select ',' + t.column_name from information_schema.columns
where table_name = 'ate1' for XML PATH ('')),1,1,'') as column
..
[/code]

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

learning_grsql
Posting Yak Master

230 Posts

Posted - 2013-06-21 : 06:35:39
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

52326 Posts

Posted - 2013-06-21 : 06:43:07
show your full code please


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

bandi
Master Smack Fu Yak Hacker

2242 Posts

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


--
Chandu
Go to Top of Page

learning_grsql
Posting Yak Master

230 Posts

Posted - 2013-06-21 : 07:31:24
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-21 : 07:37:51
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

52326 Posts

Posted - 2013-06-21 : 08:53:56
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
   

- Advertisement -