CREATE PROCEDURE [news01].[usp_generateXml]
(@email NVARCHAR(356))
AS
BEGIN TRY
DECLARE @terms TABLE(sourceName NVARCHAR(256),
url NVARCHAR(Max),
articles NVARCHAR(MAX))
INSERT INTO @terms(sourceName, url, articles)
SELECT
(SELECT source_name FROM tbl_sources),
(SELECT article_url FROM tbl_articles),
(SELECT article_id FROM news01.tbl_articles
WHERE article_title LIKE CONCAT('%',alt.term, '%'))
FROM
news01.tbl_alertTerms alt
JOIN
news01.tbl_userProfiles ussr ON (alt.profile_id = ussr.profile_id)
DECLARE @articles AS NVARCHAR(MAX)
DECLARE @sourceName AS NVARCHAR(256)
DECLARE @url AS NVARCHAR(MAX)
DECLARE cursorSearch CURSOR FOR
SELECT sourceName, url, articles
FROM @terms
OPEN cursorName
FETCH NEXT FROM cursorName INTO @sourceName, @url, @articles
WHILE @@FETCH_STATUS = 0
SELECT
sourceName AS 'SourceName',
url AS 'Url',
articles AS 'Articles'
FROM
@terms
FOR XML AUTO, ROOT('Articles');
CLOSE cursorName
I want to output the XMl raw file(xml link) using the cursor. Each user has a term(example football), the loop has to find with articles has that key word and than output the xml file with all the articles, the articles url and the source name(example BBC).The user is selected by entering his email as a parameter.
Is the cursor being implemented correctly? What am I doing wrong?
Any help would be greatly appreciated!