I would like to have xml output from Full Text Search indexed tables like below. but my code generates incorrect syntax near union my code
SELECT
Table1.Name 'Table1/Name',
Table1.Email 'Table1/Email',
( SELECT
Table2.Address 'Address',
Table2.Phone 'Phone',
FROM Details Table2
INNER JOIN Regd Table3 ON Table3.Code = Table2.Code
AND (Table3.SubCode = xml.SubCode) AND (Table1.Id = Table3.Id)
FOR XML PATH ('Details'),Type) as 'Table1',
FROM Users Table1
INNER JOIN CONTAINSTABLE(Users,[Name], @SearchKeys) AS KEY_TBL ON Id = KEY_TBL.[KEY]
INNER JOIN Regd Table3 ON Table3.Id = Table1.Id,
OPENXML (@idoc,'/Request/List',2)
WITH (SubCode NVARCHAR(20)) as xml
WHERE (xml.SubCode = '' or Table3.SubCode = xml.SubCode) AND (Table3.Id = Table1.Id)
FOR XML PATH ('List')
UNION
SELECT
SELECT
Table1.Name 'Table1/Name',
Table1.Email 'Table1/Email',
( SELECT
Table2.Address 'Address',
Table2.Phone 'Phone',
FROM Details Table2
INNER JOIN Regd Table3 ON Table3.Code = Table2.Code
AND (Table3.SubCode = xml.SubCode) AND (Table1.Id = Table3.Id)
FOR XML PATH ('Details'),Type) as 'Table1',
FROM Users Table1
INNER JOIN CONTAINSTABLE(Users,[Email], @SearchKeys) AS KEY_TBL ON Id = KEY_TBL.[KEY]
INNER JOIN Regd Table3 ON Table3.Id = Table1.Id,
OPENXML (@idoc,'/Request/List',2)
WITH (SubCode NVARCHAR(20)) as xml
WHERE (xml.SubCode = '' or Table3.SubCode = xml.SubCode) AND (Table3.Id = Table1.Id)
FOR XML PATH ('List')
here is out put i expected to have
<List>
<Table1>
<Name></Name>
<Email></Email>
<Details>
<Address></Address>
<Phone></Phone>
</Details>
</Table1>
</List>
i think request xml parameter would not be of any use here as it is just a syntax error
@idocyou're using in two places... how does that get populated, from what data?? Could you maybe simplify this to a singleSELECTand leave out theUNIONpart for now!?!?