0

I'm trying to store a query into a variable and here is what I'm doing :

@check int = [return_code] FROM [dbo].[RESULT] WHERE [code_test] = 'T3005_das'

The return code field only contains the 0 or 1 value. When I'm trying to do this, here's the error message I've got :

Msg 156, Level 15, State 1, Procedure V116_T3005, Line 7
Incorrect syntax near the keyword 'FROM'.

I don't really understand why it's not working properly as I've followed samples of code on the internet.

Any idea?

EDIT : Here's my edited procedure :

CREATE PROCEDURE V116_T3005
    DECLARE @check int 
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    SELECT @check = [code_retour] FROM [dbo].[RESULTAT] WHERE [code_test] = 'T3005_das'
    --logical code
END

Now I'm getting these errors :

Msg 156, Level 15, State 1, Procedure V116_T3005, Line 7
Incorrect syntax near the keyword 'DECLARE'.

Msg 156, Level 15, State 1, Procedure V116_T3005, Line 9
Incorrect syntax near the keyword 'AS'.

2
  • 1
    seems you missed the word SELECT Commented Mar 31, 2014 at 13:51
  • Remove Declare from your Stored Proc. Is @check your output variable? Commented Mar 31, 2014 at 15:42

2 Answers 2

1
declare @check int

select @check = [return_code] 
FROM [dbo].[RESULT] 
WHERE [code_test] = 'T3005_das'
Sign up to request clarification or add additional context in comments.

1 Comment

Thank for your help. However, I still got errors. Could you check my edit?
0

If @check is an output parameter the word declare should be omitted. If it is not it should be declared after BEGIN and if so, I would suggest:
declare @check integer = (select [code_retour] FROM [dbo].[RESULTAT] WHERE [code_test] = 'T3005_das');
BTW are you sure that select [code_retour] FROM [dbo].[RESULTAT] WHERE [code_test] = 'T3005_das' will always return one value? Otherwise error will be raised.

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.