Using a stored procedure that receives an input parameter for the Vendor state. I'm trying to cause a custom error to be thrown when the state VARCHAR value is more than 2 chars in length. I'm using the LEN function to count the parameter length and to compare the value passed to the integer 2. Logically this looks right but the error is not being thrown. Any help?
USE AP
GO
CREATE PROC TEST123
@state VARCHAR(2) = NULL
AS
IF LEN(@state) <= 2
SELECT TOP 1 VendorName
FROM Vendors
WHERE VendorState = @state;
ELSE
THROW 50001, 'Invalid state length', 1;
GO
BEGIN TRY
USE AP
EXEC TEST123 @state = 'CAA';
END TRY
BEGIN CATCH
PRINT ERROR_MESSAGE();
END CATCH