0

exec SP_HastaIcmal_AktifKaliciHastalar 25 it returns 86.

DECLARE @iAktifKaliciHastalar int

SET @iAktifKaliciHastalar = exec SP_HastaIcmal_AktifKaliciHastalar 25

that code return error.

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'exec'.

3 Answers 3

2
DECLARE @iAktifKaliciHastalar int

EXEC @iAktifKaliciHastalar = SP_HastaIcmal_AktifKaliciHastalar 25

This should work fine :-)

Sign up to request clarification or add additional context in comments.

Comments

1

Assuming the value is returned as a return code from the sproc (i.e. RETURN 86), then:

DECLARE @iAktifKaliciHastalar int
exec @iAktifKaliciHastalar = SP_HastaIcmal_AktifKaliciHastalar 25

If it's being returned as a resultset, I'd recommend changing it to being returned as a return code like above, or as an OUTPUT param (return codes can only be integers), as long as it's only ever going to return a single value.

1 Comment

DECLARE @iAktifKaliciHastalar int exec @iAktifKaliciHastalar = SP_HastaIcmal_AktifKaliciHastalar 25 print @iAktifKaliciHastalar return 86 from sp but print 0
0

In addtion to the EXEC @var = ProcName solutions, you could use output parameters which means changing your stored proc of course

DECLARE @iAktifKaliciHastalar int

EXEC SP_HastaIcmal_AktifKaliciHastalar 25, iAktifKaliciHastalar OUTPUT

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.