Why won’t my SP work THIS time?

Quick test. Why won’t this return the string “Hi”?

CREATE PROC dbo.Testing @Val VARCHAR
AS
 IF @Val = 'One'
 SELECT 'Hi' AS msg;
GO
EXEC dbo.Testing @Val = 'One';

Try it yourself, and answer in the comments. I’ll update this (in comments) in a week or so with the answer, if no one’s gotten it.

And yes, I did this exact thing. You’re never too old to do something like this.

10 thoughts on “Why won’t my SP work THIS time?”

  1. It doesn’t select “One”, it selects “Hi”.

    [Editor: This answer was right, until I edited the blog to ask the correct question.]

  2. The definition parameter @Val needs to include a length, like
    @Val VARCHAR(16)

    Otherwise, @Val is a VARCHAR(1)

Leave a Reply

Your email address will not be published. Required fields are marked *