Quotations around variable

  • Very simple question to somebodyt who knows

    declare @Databasename varchar(50)

    select @Databasename = (select DB_NAME() )

    select @Databasename

    EXECUTE master.dbo.xp_create_subdir N'W:\MSSQL10_50.LIVE802MSSQL\MSSQL\Backups\ ' + @Databasename

    I have tried a ridiculous amount of different variations of the quotations around the variable at the end but can not seem to get it right.

    Any help would be appreciated before i self distruct

  • Steveyam90 (8/6/2013)


    Very simple question

    What is your question?

    John

  • Does this work?

    DECLARE @Databasename NVARCHAR(50);

    DECLARE @Subdir NVARCHAR(150);

    SELECT @Databasename = (SELECT DB_NAME());

    --SELECT @Databasename;

    SELECT @Subdir = N'C:\Test\' + @Databasename;

    --SELECT @Subdir;

    EXECUTE master.dbo.xp_create_subdir @Subdir;

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Koen Verbeeck (8/6/2013)


    Does this work?

    DECLARE @Databasename NVARCHAR(50);

    DECLARE @Subdir NVARCHAR(150);

    SELECT @Databasename = (SELECT DB_NAME());

    --SELECT @Databasename;

    SELECT @Subdir = N'C:\Test\' + @Databasename;

    --SELECT @Subdir;

    EXECUTE master.dbo.xp_create_subdir @Subdir;

    It does indeed! thank you! Sanity saved!

  • An expression ('abc' + @z) is not permitted as a parameter to a procedure. Parameter has to be variable (or another parameter) or a constant

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 5 posts - 1 through 4 (of 4 total)

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