mk
09/07/2022, 9:04 PMi have a spx which is returning me int values as itis declated as; declare @error int
its ok to be as int, but in a case where i have to return multiple string values, i am trying to cast it to varchar so i can get the error
set @error = 'my invalid error message'
so i am trying like
set cast(@error as varchar(100)) = 'my invalid error message'
but i am getting a syntax error on the cast, am i doing anything wrongTim
09/07/2022, 9:15 PMmk
09/08/2022, 12:04 AMTim
09/08/2022, 12:11 AMDECLARE @error VARCHAR(100);
SET @error = 'my invalid error message';
Should work just fine, so there must be a different place that's the problem.
What are you doing with @error later? Are you trying to insert it into an int column or something?mk
09/08/2022, 12:14 AMmk
09/08/2022, 12:14 AMselect @error = case when substring(right('00000'+convert(varchar(6),empID),6),1,1) = '1' then 'This record is missing the ID'
else ''
end
From dbo.users EI
Where User_ID = 500
print @error;
Tim
09/08/2022, 1:07 AMmk
09/08/2022, 1:22 AMTim
09/08/2022, 1:33 AM