I have a lot of records in a table News.
Each record has NewsRoleId, NewsTitle and a URL.
The URL is like
http://ournews.com/View-News;NewsId=56122;OrderId=1;pt=5
Each NewsTitle would return you exactly 2 records; not more not less but different NewsRoleID; for example:
ID NewsTitle NewsRoleId URL
1 Test 124 http://ournews.com/View;newsId=44;OrderId=1;pt=5
`2 Test 138` http://ournews.com/View;newsId=32;OrderId=1;pt=5
Now, the goal is to UPDATE the newsId in URL by ID of one record with another i.e. Id of the record with NewsRoleID= 124 should be updated in the newsId of URL of record with NewsRoleId= 138 and vice versa.
Desired Output:
D NewsTitle NewsRoleId URL
1 Test 124 http://ournews.com/View;newsId=2;OrderId=1;pt=5
2 Test 138 http://ournews.com/View;newsId=1;OrderId=1;pt=5
I have written an update query.
Update News
SET URL= REPLACE(Url, 'newsID=123433', 'newsId='+CAST(Select Id from News where NewsTitle= 'test' and NewsRoleID= 124) as varchar)
where NewsRoleID = 138 and NewsTitle = 'test'
But Problem with this is that I cannot exactly find the pair ‘NewsId=the Id which is random’