Link to home
Start Free TrialLog in
Avatar of Jimby_Aus
Jimby_AusFlag for Australia

asked on

Exec Create Database Statement with TSql Variable and Text Qualifiers

My question is fairly straight forward, im trying to Exec an SQL statement that will create a new database, however I want to retrieve the database path from a storedprocedure and use a variable.  Along the lines of

DECLARE @dbpath nvarchar(255)
DECLARE @sql nvarchar(1000)

EXEC spsqldatabasepath @dbpath

Set @sql = 'CREATE DATABASE [dbname] ON (NAME = N'dbame.mdf', FILENAME = '+@dbpath , etc...
EXEC(@sql)

However the FILENAME clause is supposed to also have a text qualifer around it within the sql statement, how do I handle all the ' qualifiers ' and build the sql string?
ASKER CERTIFIED SOLUTION
Avatar of OMC2000
OMC2000
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jimby_Aus

ASKER

Thanks guys.