CREATE PROCEDURE dbo.YourProcedureName
AS
BEGIN
Select * from Table1 union all
Select * from Table2 union all
Select * from Table3 union all
Select * from Table4
END
Calling the SP:ASKER
DECLARE @sql nvarchar(1000)
SET @sql =
'Select * from Table1 union all
Select * from Table2 union all
Select * from Table3 union all
Select * from Table4'
EXEC sp_ExecuteSQL @sql
Of course, use your own code to populate the @sql string value-
ASKER
ASKER
ASKER
DECLARE @sql nvarchar(max)
SET @sql = N''
SELECT @sql = @sql + ' ' + <<place the expression for Det column here>>
FROM YourTable
PRINT @sql
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.
TRUSTED BY
Create Procedure proc_name as
Select * from Table1 union all
Select * from Table2 union all
Select * from Table3 union all
Select * from Table4