How to specify login and password in a script while configuring replication with TSQL

  • I know that it is not that good idea to specify login and password directly into a script, but I need to do it. In BOL it is specified this way
    SET @login = $(Login); SET @password = $(Password);
    I wonder why there is used '$' dollar sign. As both @login and @password variables are declared as sysname, shouldn't I write in text format, I mean something like this
    SET @login = 'Abcd'; and and SET @login = 'Abcd'; and SET @password = '1234';
     What's the use of dollar sign and brackets. Thanks for your time!

    Link to the BOL sourse

  • elea.grig - Thursday, December 20, 2018 6:35 AM

    I know that it is not that good idea to specify login and password directly into a script, but I need to do it. In BOL it is specified this way
    SET @login = $(Login); SET @password = $(Password);
    I wonder why there is used '$' dollar sign. As both @login and @password variables are declared as sysname, shouldn't I write in text format, I mean something like this
    SET @login = 'Abcd'; and and SET @login = 'Abcd'; and SET @password = '1234';
     What's the use of dollar sign and brackets. Thanks for your time!

    Link to the BOL sourse

    It's pretty well documented what the "$" sign is used for in the very document you linked to not to mention the environment you need to be using to use such a thing.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • there is much more to learn 
    sqlcmd.exe and/or SQLCMD mode

    https://docs.microsoft.com/en-us/sql/ssms/scripting/sqlcmd-use-with-scripting-variables?view=sql-server-2017

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply