Hello i am trying the getting result in xml format in the sql server but i don't get propare xml format many data it's repeat in xml format. i have write this query in the sql server but not a getting propare data. any one know where is my mistake then please let me know how can do that.
Here i have write this query :
select * from (
SELECT SSCF.SubSubCategoryId AS InterestId,c.FeedId,c.Description,u.UserId,u.Email,u.UserName,u.ProfileImage,u.Name,
ISNULL(SSCL.SubSubCategory,SSC.SubSubCategory) AS Interest,
1 AS [Type]
FROM SubSubCategoryFollowers SSCF
LEFT JOIN SubSubCategories SSC ON SSCF.SubSubCategoryId = SSC.SubSubCategoryId
INNER JOIN Feed c on c.FeedId = SSC.FeedId
inner join Users u on u.UserId = SSCF.UserId
WHERE u.Email is not null
UNION ALL
SELECT SCF.SubCategoryId AS InterestId,c.FeedId,c.Description,u.UserId,u.Email,u.UserName,u.ProfileImage,u.Name,
ISNULL(SCL.SubCategory,SC.SubCategory) AS Interest,
2 AS [Type]
FROM SubCategoryFollowers SCF
LEFT JOIN SubCategories SC ON SCF.SubCategoryId = SC.SubCategoryId
INNER JOIN Feed c on c.FeedId = SC.FeedId
inner join Users u on u.UserId = SCF.UserId
WHERE u.Email is not null
)as res
group by res.UserId,res.InterestId,res.FeedId,res.Description,res.Email,res.Interest,res.Type,res.UserName,res.ProfileImage,res.Name
order by res.FeedId
OFFSET 1 ROWS
FETCH NEXT 50000 ROWS ONLY
FOR XML PATH('User'), ROOT ('Users')
this is my current op =>
<Users>
<User>
<UserId>1660</UserId>
<Email>xyz.com</Email>
<UserName>xyz</UserName>
<ProfileImage>20160717035320958.jpeg</ProfileImage>
<InterestId>15</InterestId>
<FeedId>4689</FeedId>
<Description>Test</Description>
<Interest>Event</Interest>
<Type>2</Type>
</User>
<User>
<UserId>1660</UserId>
<Email>xyz.com</Email>
<UserName>xyz</UserName>
<ProfileImage>20160717035320958.jpeg</ProfileImage>
<InterestId>16</InterestId>
<FeedId>4689</FeedId>
<Description>Test</Description>
<Interest>Party</Interest>
<Type>2</Type>
</User>
<User>
<UserId>1660</UserId>
<Email>xyz.com</Email>
<UserName>xyz</UserName>
<ProfileImage>20160717035320958.jpeg</ProfileImage>
<InterestId>21</InterestId>
<FeedId>4689</FeedId>
<Description>Test</Description>
<Interest>Club</Interest>
<Type>2</Type>
</User>
<User>
<UserId>1661</UserId>
<Email>abc.com</Email>
<UserName>abc</UserName>
<ProfileImage>20160717035320959.jpeg</ProfileImage>
<InterestId>15</InterestId>
<FeedId>4690</FeedId>
<Description>Test1</Description>
<Interest>Cricket</Interest>
<Type>1</Type>
My expected o/p =>
<Users>
<User>
<UserId>1660</UserId>
<Email>xyz.com</Email>
<UserName>xyz</UserName>
<ProfileImage>20160717035320958.jpeg</ProfileImage>
<InterestId>15</InterestId>
<FeedId>4689</FeedId>
<Description>Test</Description>
<Interest>Event</Interest>
<Type>2</Type>
<InterestId>16</InterestId>
<FeedId>4689</FeedId>
<Description>Test</Description>
<Interest>Party</Interest>
<Type>2</Type>
<InterestId>21</InterestId>
<FeedId>4689</FeedId>
<Description>Test</Description>
<Interest>Club</Interest>
<Type>2</Type>
</User>
<User>
<UserId>1661</UserId>
<Email>abc.com</Email>
<UserName>abc</UserName>
<ProfileImage>20160717035320959.jpeg</ProfileImage>
<InterestId>15</InterestId>
<FeedId>4690</FeedId>
<Description>Test1</Description>
<Interest>Cricket</Interest>
<Type>1</Type>
i want like this data in xml format any one know please let me know.