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 2008 Forums
 Transact-SQL (2008)
 How to generate XML

Author  Topic 

komnaz
Starting Member

5 Posts

Posted - 2009-12-20 : 08:26:51
declare @empid varchar(10)
declare @yr varchar(10)
select @empid=EmpId, @yr=Yr from sales where Yr='2005'

select @empid,@yr --for xml auto

I want to generate @empid and @yr in XML formate

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-22 : 01:11:13
Try like this

declare @XML xml

set @XML = (select Emp_id, year from mytable for XML Auto, root('tables'), Elements)

print cast(@XML as varchar(max))

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -