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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:07:49+00:00 2026-06-07T10:07:49+00:00

In SQL Server, I have a stored procedure that accepts a date parameter. That

  • 0

In SQL Server, I have a stored procedure that accepts a date parameter. That date paramater is then passed along to another stored procedure. However, the 2nd stored procedure parameter is named as the first parameter. and then I need to I have 2 different scalar variables:

DECLARE @date date, @sql varchar(100);

SET @date = '2012-07-01';
SELECT @sql = ('EXEC pStoredprocedure @date = '''+@date+'''')

I need the @sql scalar to contain this text so the stored procedure can call the other stored procedure:

EXEC pStoredprocedure @date = '2012-07-01'

But, when I run my code above, I get this error:

Msg 402, Level 16, State 1, Line 4
The data types varchar and date are incompatible in the add operator.

It’s almost like I need to escape the @date operator. Can this be done?

Side note: Yes, I’m trying to dynamically pass along some variables. I understand the dangers of doing so, but doing it this way is much simpler…

  • 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-07T10:07:51+00:00Added an answer on June 7, 2026 at 10:07 am

    The date variable is being used in string concatenation, so it should be treated as a string, either through its declaration, a convert function, or a cast. I tried this:

     DECLARE @date varchar(20), @sql varchar(100);
    SET @date = '2012-07-01';
    SELECT @sql = ('EXEC pStoredprocedure @date = ''' + @date + '''')
    
     PRINT @sql
    

    and got this:

     EXEC pStoredprocedure @date = '2012-07-01'
    

    I am stuck on 2005, so I don’t have the date datatype, but when I tried to use datetime, I got this error:

    Msg 241, Level 16, State 1, Line 4 Conversion failed when converting
    datetime from character string.

    You can also try

     DECLARE @date datetime, @sql varchar(100);
    SET @date = '2012-07-01';
    SELECT @sql = ('EXEC pStoredprocedure @date = ''' + CONVERT(varchar(20), @date, 102) + '''')
     PRINT @SQL;
    

    and get

     EXEC pStoredprocedure @date = '2012.07.01'
    
    • 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 stored procedure that includes a DateTime parameter. This
All, I have a stored procedure on SQL Server 2005 that accepts an XML
SQL Server 2005. I have a stored procedure which accepts a few parameters that
I have a SQL Server 2000 stored procedure that accepts a number of input
On our SQL Server (Version 10.0.1600), I have a stored procedure that I wrote.
I have a SQL Server stored procedure that is not returning any data when
Let's say I have a stored procedure in Microsoft SQL Server 2005 that returns
I have an app that runs a stored procedure in SQL Server, checking the
I have a SQL Server 2008 stored procedure that updates values in a table.
I have a stored procedure for SQL Server 2000 that can only have a

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.