Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Print a SQLCMD variable in a database project?

I have a database project for SQL Server 2016. In the project properties, SQLCMD Variables tab:

Variable: $(SOURCE)
Value: MyDB

All I want to do for now is PRINT that variable.

CREATE PROCEDURE [dbo].[usp_Test]
AS
    SET NOCOUNT ON;

    PRINT [$(SOURCE)]

    RETURN 0

The project builds, I do a schema compare, then attempt to update and I get this error:

The name "MyDB" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.

Is there a way I can print the SQLCMD variables I've set up when running a stored procedure?

like image 805
Bostaevski Avatar asked Jun 04 '26 21:06

Bostaevski


1 Answers

I havent done much with this, but i have the following in one of my scripts and it works fine:

:setvar path "Variable"
PRINT '$(path)'
like image 83
Owain Esau Avatar answered Jun 06 '26 12:06

Owain Esau