May 23, 2007 at 1:04 pm
Hello,
I want to utilize a stored procedure that will accept a string variable that I will pass from my app, and utilize the LIKE operator.
I tried this:
Declare @NAMEX varchar
Set @NAMEX = 'S'
Select @NAMEX = @NAMEX + '%'
SELECT VENDORNO, NAMEX, STREET, CITY, STATE, ZIP,
FROM VENDORDFROM
WHERE NAMEX Like @NAMEX
ORDER BY NAMEX
and it returns, of course, zero rows. Replacing the variable code with 'S' returns data.
Can you please help with the proper syntax?
Thanks so much.
May 23, 2007 at 1:13 pm
Which version of SQL you are using? I just tried your query now in SQL 2000 and working fine.
May 23, 2007 at 1:14 pm
2000
May 23, 2007 at 1:17 pm
Starnge..Its working fine in 2000 when i tried. can you try running the query again?
The code i tried is
Declare @NAMEX varchar(100)
Set @NAMEX = 'S'
Select @NAMEX = @NAMEX + '%'
SELECT * FROM testTbl WHERE NAMEX Like @NAMEX ORDER BY NAMEX
Got your problem..make varchar(50) when you declare variable..
May 23, 2007 at 1:23 pm
BINGO! That did it. Thanks. That was driving me crazy!
Mike
May 23, 2007 at 2:07 pm
You can also simplify this...
Declare @NAMEX varchar(100)
Set @NAMEX = 'S'
SELECT * FROM testTbl WHERE NAMEX Like @NAMEX + '%' ORDER BY NAMEX
cheers
Ben Sullins
bensullins.com
Beer is my primary key...
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply