*UPDATE *
The scope has now developed slightly, and I now need to retreive the fields ‘Id, uri, linkTo’. How does this change things???
I’m using an MS-SQL 2005 db and have the following stored procedure;
CREATE PROCEDURE dbo.getNewAds
(
@region
)
AS
BEGIN
SELECT TOP 1 Id, uri, linkTo FROM Adverts
ORDER BY NEWID()
WHERE adRegion = @region
END
I would like to then add ‘1’ to the column named adShown in the same table, for the single result retrieved. What is the simplest / quickest means to do this within the same procedure?
Thanks in advance for any help you can offer.
There is a quirky update syntax that will let you assign the value to a variable at the same time as performing an update, but I’m not going to show it to you because it is undocumented, unsupported, and I can’t guarantee that it will continue to work in future versions of SQL Server. Here is the method I would recommend (assuming Id is PK or at least unique):