3

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?

2
  • Might be enough to use qoutes around... Commented Jan 18, 2017 at 17:35
  • OMG... you are right. I had tried PRINT '''' + [$(SOURCE)] + '''' which also failed. But when I just now tried it this way it worked: PRINT '[$(SOURCE)]' THANKS! Commented Jan 18, 2017 at 17:44

1 Answer 1

4

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)'
Sign up to request clarification or add additional context in comments.

1 Comment

Double quotes to define the variable and single quotes for the print statement! Thank you

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.