0

I have a big problem that I don't understand.

I have this query in Tsql :

SET @sSQL = 'SELECT * 
  INTO '+@sTableValeursDefaut+' 
  FROM OPENQUERY(LINKSVR_LOCAL , '' SET FMTONLY OFF 
  EXEC [AIGP].[dbo].[rp_WEB_ValeursDefaut_Get] 
  '''''+'sds'+''''',
  '+ISNULL(CONVERT(VARCHAR, @fkIDProjet), 'NULL+')+',
  '+'123'+''')'

EXEC(@sSQL)

This work perfectly. But when I change the '123' for CONVERT(VARCHAR, @fkIDCfgFormulaire) and the 'sds' to @sNoUsager the query don't work !

SET @sSQL = 'SELECT * 
  INTO '+@sTableValeursDefaut+' 
  FROM OPENQUERY(LINKSVR_LOCAL , '' SET FMTONLY OFF 
  EXEC [AIGP].[dbo].[rp_WEB_ValeursDefaut_Get] 
  '''''+@sNoUsager+''''',
  '+ISNULL(CONVERT(VARCHAR, @fkIDProjet), 'NULL+')+',
  '+CONVERT(VARCHAR, @fkIDCfgFormulaire)+''')'

EXEC(@sSQL)

What I am doing wrong ?

1 Answer 1

1

Without more information it's difficult to tell. Could be anything from the datatypes of the variables to the value of the variables you are passing...

We could do with some test data please.

It may also be that you have a '+' character in your literal I haven't tested it but 'NULL+' should probably read 'NULL'

Or it could be because in your CONVERT(VARCHAR, @fkIDProjet) you don't give a length to your varchar try something like this instead CONVERT(VARCHAR(5), @fkIDProjet)

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.