4

I am trying to concatenate a parameter of my stored procedure inside a query but it always keeps showing an error . This my query:

EXEC xp_cmdshell 'bcp "SELECT matriculeEmployeur,
                              cleEmployeur,
                              codeDexp,
                              trimestre,
                              annee,
                              page,
                              ligne,
                              matriculeAssure,
                              cleAssure,
                              CONCAT(CONCAT(nom,nomPere,prenom),space(60-LEN(CONCAT(nom,nomPere,prenom)))),
                              carteIdentity,
                              salaire 
                              FROM ##myTempo" queryout "FILEPATH"' +fname+ '-c -T'.

The error is shown on the first concatenation symbol [the first plus sign]. What error did I make here?

2
  • Maybe this is because fname without an @ in front is not a valid parameter. Commented Sep 17, 2017 at 17:20
  • I added the @ but the errors keeps showing. Commented Sep 17, 2017 at 17:34

1 Answer 1

6

First construct the command in a VARCHAR variable, then use the variable in your exec statement. You can't concatenate strings in place of a stored procedure parameter.

DECLARE @cmd VARCHAR(8000);
SET @cmd=...; -- build your command shell command here
EXEC xp_cmdshell @cmd;
Sign up to request clarification or add additional context in comments.

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.