SQL: 2008 Compatability: SQL 2008 OS: Vista The following query works just fine and produces an XML:
with Q1 as
(select Job, Site from JJobs where Job > 602700)
select * from Q1 where Job = 602720
for xml path('Detail'), type
I need to put this into a function that returns an XML variable so, I change to:
declare @xOut XML;
set @xOut =
with Q1 as
(select Job, Site from JJobs where Job > 602700)
select * from Q1 where Job = 602720
for xml path('Detail'), type
This produces the error: Incorrect syntax near the keyword 'with'. The query works but the assignment errors and indicates a problem with the query. Any ideas?