SQL command mode SQL SERVER - unable to Print

2019-08-28 08:03发布

问题:

I am trying to run these commands and I am getting below result. A single quote ('GetDetailsToSendApprovalMail.sql ) keeps appearing in o/p, now matter what I try. Please let me know what I am doing wrong ?

:setvar ScriptPath 'C:\ProjectWork\DatabaseFiles\DEV\23OctScriptDev\'

:setvar SQLFile 'GetDetailsToSendApprovalMail.sql'


 PRINT $(ScriptPath)'GetDetailsToSendApprovalMail.sql'
 PRINT $(ScriptPath)$(SQLFile)

output:

C:\ProjectWork\DatabaseFiles\DEV\23OctScriptDev\'GetDetailsToSendApprovalMail.sql C:\ProjectWork\DatabaseFiles\DEV\23OctScriptDev\'GetDetailsToSendApprovalMail.sql

回答1:

Please use + as concatenation operator like below:

PRINT $(ScriptPath)+$(SQLFile)


回答2:

You should concatenate the strings using +:

:setvar ScriptPath 'C:\ProjectWork\DatabaseFiles\DEV\23OctScriptDev\'

:setvar SQLFile 'GetDetailsToSendApprovalMail.sql'

 PRINT $(ScriptPath)+'GetDetailsToSendApprovalMail.sql'
 PRINT $(ScriptPath)+$(SQLFile)