Reputation: 7299
I want to declare a VARCHAR
variable in MSSQL that can hold this
set @RaiseErrorMessage =
('ErrorNumber='+(cast((select ERROR_NUMBER()) as varchar(100)))+
,ErrorSeverity='+ (cast((select ERROR_SEVERITY()) as varchar(100)))+
',ErrorState='+(cast((select ERROR_STATE()) as varchar(100)))+
',ErrorLine='+(cast((select ERROR_LINE()) as varchar(100)))+
,ErrorMessage='+(cast((select ERROR_MESSAGE()) as varchar(100))))
How should the declaration look for an variable like this? I tried
declare @RaiseErrorMessage varchar
but it didn't help.
Upvotes: 18
Views: 79458
Reputation: 9016
You'll need to declare the length of the variable:
DECLARE @RaiseErrorMessage VARCHAR(500)
SET @RaiseErrorMessage=' ...... '
Upvotes: 31