Skip to content

variable declaration with cte #447

Open
@jtougas

Description

@jtougas

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions