If you don’t specify a variable length for NVarchar, Varchar variables, the parser will assume the length of 1.
It will not complain. Instead it will just truncate whatever you pass to the variable and use the first character.
This mistake can cost you lots of time. Especially if you are working on a stored procedure with a complex SQL query.
You will think you made a mistake in your stored procedure and it could be hours when you actually realize this 🙂
… … -- DON’T USE THIS @NephFilter varchar, @ElsewhereFilter varchar … …
… … -- USE THIS @NephFilter varchar(1), -- SPECIFY THE LENGTH. EVEN IF IT’S 1 SO YOU WILL PRACTICE THIS @ElsewhereFilter varchar(100) … …
2 thoughts on “Importance Of Specifying Variable Length For Varchar in SQL Stored Procedures”
Great blog, Keep up the quality work!
Fantastic post however I was wondering if you could write a litte more on this topic? I’d be very grateful if you could elaborate a little bit more. Thank you!