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

  • Home
  • SEARCH
  • 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 8101093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:54:07+00:00 2026-06-05T22:54:07+00:00

I am missing something in my SQL query, could please someone advise how to

  • 0

I am missing something in my SQL query, could please someone advise how to do correct it? This is my SQL:

declare @numItems int;
declare @value1 int;
declare @value2 int;
declare @currentValue int;
declare @counter int;
declare @qry nvarchar(max)

set @value1 = 5;
set @value2 = 10;

set @numItems = 2
set @counter=0

WHILE (@counter < @numItems)
BEGIN
    set @qry = 'set @currentValue = @value' + cast(@counter+1 as nvarchar(max)) + ';'   
    exec sp_executesql @qry, N'@currentValue int OUTPUT', @currentValue OUTPUT

    print @currentValue

    set @counter = @counter + 1;
END

What I want is that @currentValue parameter gets values of @value1 and @value2 and prints them.
I’m not sure how to correctly declare parameters in the exec statement. I am using SQL Server 2005. Thanks for any help.

  • 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-06-05T22:54:08+00:00Added an answer on June 5, 2026 at 10:54 pm
    declare @numItems int;
    declare @value1 int;
    declare @value2 int;
    declare @currentValue int;
    declare @counter int;
    declare @qry nvarchar(max)
    
    set @value1 = 5;
    set @value2 = 10;
    
    set @numItems = 2
    set @counter=0
    
    WHILE (@counter < @numItems)
    BEGIN
        set @qry = 'set @currentValue = @value' + cast(@counter+1 as nvarchar(max)) + ';'   
        exec sp_executesql @qry, 
                            N'@value1 int, @value2 int, @currentValue int OUTPUT', 
                            @value1=@value1,@value2=@value2, @currentValue = @currentValue OUTPUT
    
        print @currentValue
    
        set @counter = @counter + 1;
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this SQL query is wrong, or I am missing something, but I
I know SQL well but I must be missing something really dumb here. This
I have a SQL query, looks something like this: select name, count (*) from
Can someone explain to me what syntax this SQL query matches? SELECT DISTINCT boats.boatid
I'm fairly new to LINQ to SQL, so I could be missing something basic
I'm having a hard time wrapping my head around this Django query. I could
I am missing something simple I am sure. This is the first time I
I have a problem with an SQL query on Postgresql. This select clause is
Probably missing something completely obvious here, but here goes. I'm starting out with Spring
either I'm missing something or the ( patterns & practices Composite Application Guidance for

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.