I’ve got a script that I’ve created for our production line where the user enters some variables into the script before executing. The Problem is that the variables are NVARCHAR(9) and if the user inputs a 10 character sting the last character is cut off (as expected) what I want to know is how can I have SQL throw an error if they enter a value that is too long? This issue stems from users fat fingering their inputs. Example:
Valid input - DECLARE @ClientCode NVARCHAR(9) SET @ClientCode = N'ABCDEFGHI' SELECT @ClientCode Results ABCDEFGHI Invalid input –
DECLARE @ClientCode NVARCHAR(9) SET @ClientCode = 'ABCDDEFGHI' SELECT @ClientCode Results ABCDDEFGH What I’m hoping for is a setting that will have SSMS raise an error. What I’m hoping to avoid is something like -
DECLARE @ClientCode NVARCHAR(50) ... IF LEN(@ClientCode) > 9 RAISERROR('Too long dummy.',16,1)
Thanks for you help