Avatar of CipherIS
CipherISFlag for United States of America

asked on 

SQL Add Parameter in Variable

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?
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
CipherIS
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of CipherIS
CipherIS
Flag of United States of America image

ASKER

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.
SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of CipherIS
CipherIS
Flag of United States of America image

ASKER

Decided to use the THROW as RIASEERROR is not the most current.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo