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 2000 Forums
 SQL Server Development (2000)
 Why this doesn't work?

Author  Topic 

Sajesh.kumar
Starting Member

3 Posts

Posted - 2009-02-03 : 04:38:50
declare @chkval
set @chkval = (select 1 as tag,null as parent,stud_id as [StudentDetails!1!id],fname as [StudentDetails!1!First Name!Element]
from student_details StudentDetails for xml explicit)

when i am trying to execute it gives incorrect syntax near xml

Can any body help me out to figure out the problem.

Sajesh Kumar

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-03 : 04:50:49
declare the datatype for @chkval
Go to Top of Page

AvanthaSiriwardana
Yak Posting Veteran

78 Posts

Posted - 2009-02-03 : 04:51:38
use FOR XML RAW

Avantha Siriwardana
Beware of bugs in the above code; I have only proved it correct, not tried it.
(Donald Knuth)
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-03 : 04:54:23
its working i have taken some sample data and works in sql2005 and sql query analyzer also
declare @temp table (Id int, FirstName varchar(32))
insert into @temp
select 1, 'FirstName1' union all
select 2, 'FirstName2' union all
select 3, 'FirstName3' union all
select 4, 'FirstName4' union all
select 5, 'FirstName4' union all
select 6, 'FirstName4' union all
select 7, 'FirstName4'

declare @chkval varchar(32)
select @chkval = (select 1 as tag,null as parent,id as [StudentDetails!1!id],FirstName as [StudentDetails!1!First Name!Element]
from @temp StudentDetails for xml explicit)
select @chkval
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-03 : 10:16:57
quote:
Originally posted by bklr

its working i have taken some sample data and works in sql2005 and sql query analyzer also
declare @temp table (Id int, FirstName varchar(32))
insert into @temp
select 1, 'FirstName1' union all
select 2, 'FirstName2' union all
select 3, 'FirstName3' union all
select 4, 'FirstName4' union all
select 5, 'FirstName4' union all
select 6, 'FirstName4' union all
select 7, 'FirstName4'

declare @chkval varchar(32)
select @chkval = (select 1 as tag,null as parent,id as [StudentDetails!1!id],FirstName as [StudentDetails!1!First Name!Element]
from @temp StudentDetails for xml explicit)
select @chkval



did you check in sql 2000?
b/w this is sql 2000 forum so i guess op is using sql 2000
Go to Top of Page
   

- Advertisement -