I have a stored procedure with an input variable that I would like check if it only contains numbers or commas, and if it doesn't, throw an error. Ex's of the what the variable string could be:
@inputvariable = 489
@inputvariable = 489,504
I'm trying to do something like:
IF (@inputvariable NOT LIKE '%[0-9]%' OR @inputvariable NOT LIKE '%,%')
BEGIN
RAISERROR ('@inputvariable can only contain numbers and commas', 18, 1)
RETURN
END
If the variable contains at least 1 number or 1 comma, it doesn't through an error even if there are "invalid" characters. What am I doing wrong?
1条答案
按热度按时间6ss1mwsb1#
You may use the pattern
[^0-9,]
:The above would raise an error whenever the input variable contains a character which is not a digit or comma.