mssql-cli icon indicating copy to clipboard operation
mssql-cli copied to clipboard

variable declaration with cte

Open jtougas opened this issue 5 years ago • 1 comments

I'm having trouble declaring a variable and a cte in one statement. This is something that works with sqlcmd.

Statement

STMT=$(cat <<'EOF'
DECLARE @bar INT = 1
;with foo as (select @bar as foo)
select * from foo
GO
EOF
)

sqlcmd

$ sqlcmd -S sqlserver.corp.com -U username -P password -Q "${STMT}"
foo        
-----------
          1

(1 rows affected)

mssql-cli

$ mssql-cli --username username --password password --server sqlserver.corp.com --query "${STMT}"
Commands completed successfully.
Msg 137, Level 15, State 2, Line 2
Must declare the scalar variable "@bar".

jtougas avatar Apr 06 '20 13:04 jtougas

I've repro'd the bug on my end. mssql-cli is able to print the scalar value as long as it's not referenced in a CTE.

Thank you @jtougas for letting us know about this bug!

ellbosch avatar Apr 08 '20 00:04 ellbosch