0

I'm trying to execute next query

DECLARE @ponumber varchar(50)
DECLARE @gcas varchar(50)
SET @ponumber = '3864_ab03963'
SET @gcas = '81332119.'
EXEC(N'SELECT * FROM tCleanOrderTracking_prod 
       WHERE [PO number] = ' + @ponumber + ' AND [GCAS] = ' + @gcas)

And I've got an error message

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '_ab03963'.

What I'm doing wrong?

1

3 Answers 3

2

You have to close the single quote after the @gcas parameter.

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

Comments

1

Try this you missed ' near @gcas.

DECLARE @ponumber varchar(50)
DECLARE @gcas varchar(50)
SET @ponumber = '3864_ab03963'
SET @gcas = '81332119.'
EXEC(N'SELECT * FROM tCleanOrderTracking_prod 
       WHERE [PO number] = ' + @ponumber + ' AND [GCAS] = ' + @gcas + ')

Comments

1

You should enclose with quotes your all string parameters, For example:

quote(@gcas) instead of simple @gcas

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.