3

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?

1 Answer 1

2
declare @xOut XML;

with Q1 as
(
  select Job, Site 
  from JJobs 
  where Job > 602700
)
select @xOut = (
               select * 
               from Q1 
               where Job = 602720
               for xml path('Detail'), type
               );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.