csharpenthusiast007
Programmer
Hi, I am working on creating a view dynamically from many different database. For instance search through all the user database and look for view with prefix "view_Dim_" and create the view on ReportDB Database. Please give me ideas on how to accomplish this.
DECLARE @Database SYSNAME
SET @Database = 'ReportDB'
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = 'USE '+ QUOTENAME(@Database ) +';
EXEC(''
CREATE VIEW [dbo].[MyTable] AS
SELECT 1 AS [Col]
'')'
EXEC (@SQL)
Thank you.
DECLARE @Database SYSNAME
SET @Database = 'ReportDB'
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = 'USE '+ QUOTENAME(@Database ) +';
EXEC(''
CREATE VIEW [dbo].[MyTable] AS
SELECT 1 AS [Col]
'')'
EXEC (@SQL)
Thank you.