We help IT Professionals succeed at work.

SQL Add Parameter in Variable

CipherIS
CipherIS asked
on
85 Views
Last Modified: 2017-04-10
Trying to add a parameter in my variable.  Having an error after the comma.  Says - "Incorrect syntax near Convert expected vairable".  Also receiving an error on VARCHAR, states expecting select.
DECLARE @msg VARCHAR(50) = 'The part number is not the correct length.  The length should be {0} ', CONVERT(VARCHAR, @PartLength);  
IF @Length <> @PartLength 
    THROW 50001, @msg, 1;

Open in new window

How do I resolve this?
Comment
Watch Question

Sr. System Analyst
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
That works.  I originally had @msg in the RAISEERROR.  

I thought that you could add {0} with a comma to fill in the parameter in the correct location.
HainKurtSr. System Analyst
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Decided to use the THROW as RIASEERROR is not the most current.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.