2

I built a single stored procedure like this:

create proc sp_test
  (@name nvarchar(100))
as
begin
    select * from company
    where company.companyname like '%'+@name+'%'
end
go

Now I want to test my stored procedure. Because the company name might have a single quote, such as: Bob's Warehouse, I use this name as a parameter to run my stored procedure in different environments like DEV, SIT, UAT. I replace single quotes with 2 single quotes. I found I can get results in DEV, but not in UAT. I don't know why.

exec sp_test 'Bob''s Warehouse'

Is this anything about database settings in the different environment? Why does the exact same code work in one environment but not the other?

Thanks in advance.

7
  • 3
    Probably nothing to do with the quote. Different data? different collations (e.g. case sensitivity)? Nov 30, 2012 at 17:26
  • you might want to read about Set quoted_identifier in BOL
    – HLGEM
    Nov 30, 2012 at 17:59
  • I check the collation is same.
    – howexg9
    Nov 30, 2012 at 18:01
  • Is the data the same? Does the UAT database contain a record for Bob's Warehouse? Nov 30, 2012 at 18:02
  • This is just a very simple example to explain why it doesn't work. In the real world, whenever the input parameter has value with single quote, the related records won't be retrieved. So I don't think it's about case sensitivity issue, because all those parameters value are coming from table.
    – howexg9
    Nov 30, 2012 at 18:09

1 Answer 1

0

If it is just because of single quote, it doesn't make sense working on one environment not another. Try to backup and restore the same data on different environment and give it a try, this probably is because of dirty data. If you have specific record like [Bob's Warehouse] doesn't work on different environment, try to check if the single quote you see is really char(39). You can also try run [exec sp_test 'Bob' + char(39) + 's Warehouse' ] on different environment see if it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.