I have this code here:
DECLARE @inputform varchar
SET @inputform = 'J61807017B'
SELECT * FROM test where text1 LIKE '@inputform'
This won't give me the desired output, but when i do like this it works:
DECLARE @inputform varchar
SET @inputform = 'J61807017B'
SELECT * FROM test where text1 LIKE 'J61807017B'
Any idea?
You need to specify the size of the variable and drop the quotes when you use it:
DECLARE @inputform varchar(20)
SET @inputform = 'J61807017B'
SELECT * FROM test where text1 = @inputform
-- or text1 like '%'+ @inputform +'%' if you want to do partial matching
If you don't specify the size for a char/varchar value the size will be 1.
From the manual:
When n is not specified in a data definition or variable declaration statement, the default length is 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With