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. Jules

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

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

  2. Dan Kearney

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

    Otherwise, @Val is a VARCHAR(1)

  3. Jules

    Needs to define the varchar length! Easy to see in a tiny query … easy to miss in a larger script.

Comments are closed.