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
 Error on temp data

Author  Topic 

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-05-06 : 08:28:27
Kindly help me to fix the error in the below query..
i am getting error when i execute section : select v.alais_name from(
Query ::
=========
select v.alais_name from(
SELECT cast(c.UpdateSql as varchar(max)) alais_name
FROM
(select '[' +column_name +']' + ' = Replace([' + column_name + '],''"'', ''''), ' UpdateSql
from information_schema.columns
where table_name = 'dim_employee') c
for xml path(''), type ) v


Error Message :
==============
Msg 8155, Level 16, State 2, Line 8
No column name was specified for column 1 of 'v'.
Msg 207, Level 16, State 1, Line 2
Invalid column name 'alais_name'.


THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-05-06 : 08:57:13
fixed :
set @strsql=( select (
SELECT cast(c.UpdateSql as varchar(max)) dfee
FROM
(select '[' +column_name +']' + ' = Replace([' + column_name + '],''"'', ''''), ' UpdateSql
from information_schema.columns
where table_name = 'dim_employee') c
for xml path(''), type).value('.', 'VARCHAR(MAX)') str_update)

THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-05-06 : 08:59:09
quote:
Originally posted by shanmugaraj

Kindly help me to fix the error in the below query..
i am getting error when i execute section : select v.alais_name from(
Query ::
=========
select v.alais_name from(
SELECT cast(c.UpdateSql as varchar(max)) alais_name
FROM
(select '[' +column_name +']' + ' = Replace([' + column_name + '],''"'', ''''), ' UpdateSql
from information_schema.columns
where table_name = 'dim_employee') c
for xml path(''), type ) v


Error Message :
==============
Msg 8155, Level 16, State 2, Line 8
No column name was specified for column 1 of 'v'.
Msg 207, Level 16, State 1, Line 2
Invalid column name 'alais_name'.


THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

I didn't follow the logic you are implementing. However, the syntax error can be removed by specifying the column name as shown below:
....
where table_name = 'dim_employee') c
for xml path(''), type ) v(alais_name)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-07 : 00:21:17
looks like attempt is to generate a column list from columns in dim_employee table but didnt understand purpose of replace logic though

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

- Advertisement -