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 6368953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:44:29+00:00 2026-05-25T00:44:29+00:00

@RowFrom int @RowTo int are both Global Input Params for the Stored Procedure, and

  • 0

@RowFrom int

@RowTo int

are both Global Input Params for the Stored Procedure, and since I am compiling the SQL query inside the Stored Procedure with T-SQL then using Exec(@sqlstatement) at the end of the stored procedure to show the result, it gives me this error when I try to use the @RowFrom or @RowTo inside the @sqlstatement variable that is executed.. it works fine otherwise.. please help.

"Must declare the scalar variable "@RowFrom"."

Also, I tried including the following in the @sqlstatement variable:

'Declare @Rt int'
'SET @Rt = ' + @RowTo

but @RowTo still doesn’t pass its value to @Rt and generates an error.

  • 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-25T00:44:30+00:00Added an answer on May 25, 2026 at 12:44 am

    You can’t concatenate an int to a string. Instead of:

    SET @sql = N'DECLARE @Rt int; SET @Rt = ' + @RowTo;
    

    You need:

    SET @sql = N'DECLARE @Rt int; SET @Rt = ' + CONVERT(VARCHAR(12), @RowTo);
    

    To help illustrate what’s happening here. Let’s say @RowTo = 5.

    DECLARE @RowTo int;
    SET @RowTo = 5;
    
    DECLARE @sql nvarchar(max);
    SET @sql = N'SELECT ' + CONVERT(varchar(12), @RowTo) + ' * 5';
    EXEC sys.sp_executesql @sql;
    

    In order to build that into a string (even if ultimately it will be a number), I need to convert it. But as you can see, the number is still treated as a number when it’s executed. The answer is 25, right?

    In modern versions you can use CONCAT() to avoid handling NULL or conversion issues:

    SET @sql = CONCAT(N'SELECT ', @RowTo, ' * 5');
    

    But in your case you should use proper parameterization rather than concatenation. If you keep using concatenation, you will expose yourself to SQL injection at some point (see this and this):

    SET @sql = @sql + ' WHERE RowNum BETWEEN @RowFrom AND @RowTo;';
    
    EXEC sys.sp_executesql @sql,
      N'@RowFrom int, @RowTo int',
      @RowFrom, @RowTo;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a SQL Server query: declare @TaxYear VARCHAR(50) set @TaxYear='13' declare @BBL
In the below Stored procedure, i am returning a row if all the conditions
I have the following SQL Server query and I am trying to get the
I have this proc: Create PROCEDURE [dbo].[myProc] @TableName nvarchar(100), @RowID int AS BEGIN SET
So, I'm writing this Stored Proc and I really suck at SQL. My Question
I am getting random row from my table using the following query: SELECT value_id
I am reading a row from a SQL Server table. One of the columns
I'd like to write a MySQL stored function that returns multiple rows of data.
Table1 ID INT Tags TEXT Table2 ID INT Tags TEXT The tags field could
I have a query that returns a bunch of rows. But using the same

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.