sql - Get database name from field? -
currently reference multiple databases same query, so
databasename.tablename.column
i wondering if can reference database name field. reason there hundreds of these references , when creating new instances customers database names vary slightly, these have updated.
what looking this:
(select databasename configurationtable).tablename.columnname
would work @ all? , if can foresee problems?
you cannot use syntax in question.
what use dynamic sql , build query dynamically based on database name. example:
declare @sql nvarchar(max) = (select databasename configurationtable) set @sql = n'select columnname ' + quotename(@sql) + n'..tablename' exec sp_executesql @sql
Comments
Post a Comment