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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:37:18+00:00 2026-06-07T01:37:18+00:00

I have a stored procedure that takes two parameters as varchar(50) . The stored

  • 0

I have a stored procedure that takes two parameters as varchar(50). The stored procedure does a few simple queries into a temp table and the returns the result set from the temp table (I removed the actual queries)

ALTER PROCEDURE [dbo].[cv_GetBooks]
    @bookNumber as varchar(50),
    @bookDate as varchar(50)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    --a few select statements

    if @ismultiple = '0'
    begin
         select * from books where bookNumber = @bookNumber
    and bookDate = @bookDate
    and Bookname is  not null
    end
    ELSE
    Begin
        select * into #temp from books
    where bookNumber = @bookNumber
    and bookDate = @bookDate
    and Bookname is   null

           select * from books
    where bookauthor not in (select bookauthor from #temp) 
    and bookNumber= @bookNumber
            and bookDate= @bookDate
        drop table #temp
    end
END

I have this query installed on my local development machine on SQL Server 2008. I have also installed it on a two test machines running Windows Server 2003 and SQL Server 2008. The stored procedure has been working as expected.

cv_GetBooks '012345678', '06062012' --returns result set as expected

I recently moved it to a test server in another remote environment that is running Windows server 2008 and SQL Server 2008 R2. The stored procedure no longer works as expected. After running SQL Profiler I have confirmed that the same code is being executed:

cv_GetBooks '012345678', '06062012' --run on SQL server 2008 r2 returns nothing

When I removed the quotes from the query I got the expected result:

cv_GetBooks 012345678, 06062012 --run with out quotes server returns expected result set

I have since installed the same stored procedure on local version of SQL Server 2008 R2 and everything is running as expected, with the literal string quotes in place, as in the first example.

At first I thought it was an escape issue with the passed parameters but that doesn’t seem correct because the passed values are do not contain any single quotes.

Having installed and had it working on so many environments, I am under the impression that this is maybe a setting in SQL Server that I am unaware of.

What could be causing the stored procedure to not return the result set with the string literals in place on the SQL Server 2008 r2 instance, but work correctly with out them there?

  • 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-07T01:37:20+00:00Added an answer on June 7, 2026 at 1:37 am

    You did not post the table definition of table Books, but

    cv_GetBooks '012345678', '06062012' 
    --run on SQL server 2008 r2 returns nothing
    
    cv_GetBooks 012345678, 06062012 
    --run with out quotes server returns expected result set
    

    could be caused if BookNumber and BookDate were numeric rather than varchar:

    Leading zero in ints is dropped, and when converted to varchar the resulting string does not contain the leading zero.

    It’s also not clear how the data in your table affects the execution (IF statement!) in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that takes no parameters, and it returns two fields.
i have a stored procedure that takes 2 parameters: ID and Date. when i
I have a stored procedure that takes in the name of a table as
I have a stored procedure in a MS-SQL 2005 database that: Creates two temp
I have an Oracle stored procedure which takes two parameters: a custom data type
I have a stored procedure that takes a user ID and calculates their balance
I have a stored procedure that has the parameter: @desk VARCHAR(50) I want to
I have a stored procedure that takes a single parameter of data-type XML. I
I have a mysql 5.1, stored procedure that takes TEXT input which is supposed
I have a stored procedure that takes a uniqueidentifier as parameter. It is supposed

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.