Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6125815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:17:30+00:00 2026-05-23T16:17:30+00:00

* UPDATE * The scope has now developed slightly, and I now need to

  • 0

*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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:17:30+00:00Added an answer on May 23, 2026 at 4:17 pm

    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):

    DECLARE 
      @Id INT, 
      @uri VARCHAR(2048),
      @linkTo VARCHAR(2048);
    
    SELECT TOP 1 @Id = Id, @uri = uri, @linkTo = linkTo
      FROM dbo.Adverts
      WHERE adRegion = @region
      ORDER BY NEWID();
    
    UPDATE dbo.Adverts
      SET adShown = adShown + 1
      WHERE Id = @Id;
    
    SELECT Id = @Id, uri = @uri, linkTo = @linkTo;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
Now I realise this topic has been covered many times before. However there did
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update : Looks like the query does not throw any timeout. The connection is
Update: Please read this question in the context of design principles, elegance, expression of
I'm trying to manually update a db in Spree, but it has no model
This question has been asked a lot of times in many forums. But I
Right now I have this social media app, where I'm implementing ratings on users
This has been discused on SOF, though, I didn't find anyone having exactly the
Carrying on from my previous question, which has now been solved: Issue with Pointers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.