patternsqlModerate
Stored procedure parameters using tsql functions?
Viewed 0 times
storedtsqlprocedureusingfunctionsparameters
Problem
Environment sql server 2005 sp3
I have a stored proc that takes an INT as input. I want to CAST a CHAR to an INT during the call to the stored proc. it seems I cannot do that. I get a syntax error before @foo. I do not see it can someone help me find it please. Thank you very much.
I have a stored proc that takes an INT as input. I want to CAST a CHAR to an INT during the call to the stored proc. it seems I cannot do that. I get a syntax error before @foo. I do not see it can someone help me find it please. Thank you very much.
CREATE PROCEDURE testme
@test AS INT
AS
BEGIN
SELECT @TEST
END
DECLARE @foo AS CHAR(6)
set @foo = '11test'
EXEC testMe @test = CAST(Substring(@foo,1,2) as int)Solution
Why not do the CAST when you SET @foo instead?
You could even use a second variable and do this:
and then just call the proc:
SET @foo = CAST(Substring('11test',1,2) as int)You could even use a second variable and do this:
SET @foo1 = '11test'
SET @foo2 = CAST(Substring(@foo1,1,2) as int)and then just call the proc:
EXEC testMe @test = @foo2Code Snippets
SET @foo = CAST(Substring('11test',1,2) as int)SET @foo1 = '11test'
SET @foo2 = CAST(Substring(@foo1,1,2) as int)EXEC testMe @test = @foo2Context
StackExchange Database Administrators Q#2545, answer score: 10
Revisions (0)
No revisions yet.