tsql - How do I use an SQLCMD variable to define a table name? -
so, using ssdt on visual studio 2013, can specify database name...
create view vsample1 select * [$(randomdatabase)].dbo.tablename
i can 4 part name
create view vsample2 select * [$(randomserver)].[$(randomdatabase)].dbo.tablename
but when try tablename, errors...
create view vsample3 select * [$(randomserver)].[$(randomdatabase)].dbo.[$(randomtable)]
it gives me error similiar
error: sql71561: view: [vsample3] has unresolved reference object [$(randomserver)].[$(randomdatabase)].dbo.[$(randomtable)].
i've been looking @ sqlcmd variables window in project settings , have verified $(randomtable) variable defined tablename, still gives me build errors.
why this, , how fix it?
thanks
i use pre/post deployment script create such view using sp_executesql , dynamic query.
exec sp_executesql n'create view vsample3 select * [$(randomserver)].[$(randomdatabase)].dbo.[$(randomtable)]'