Hi Forum,
I have an SP that uses a table to retrive data from many tables.
SET QUOTED_IDENTIFI ER OFF
GO
SET ANSI_NULLS ON
GO
Alter Procedure [dbo].[Fetch_Table_Dat a]
AS
Begin
-- Declare the variables to store the values returned by FETCH.
DECLARE @Table varchar(8000);
declare @cmd varchar (8000);
set @cmd = ''
DECLARE Table_cursor CURSOR FOR
SELECT distinct ProjektTabelle
FROM dbo.T_TProjekte ;
OPEN Table_cursor;
-- Perform the first fetch and store the values in variables.
-- Note: The variables are in the same order as the columns
-- in the SELECT statement.
FETCH NEXT FROM Table_cursor
INTO @Table;
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
-- Concatenate and display the current values in the variables.
if @cmd <> ''
set @cmd = @cmd + ' union '
set @cmd = @cmd + 'Select CNI,CPROJEKT from ' + @Table
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM Table_cursor
INTO @Table
exec(@cmd)
END
CLOSE Table_cursor
DEALLOCATE Table_cursor
END
GO
SET QUOTED_IDENTIFI ER OFF
GO
SET ANSI_NULLS ON
GO
Ho would I go about changing this SP to a Function that RETURNS A list of all Records?
thanks in advance
Jeff
I have an SP that uses a table to retrive data from many tables.
SET QUOTED_IDENTIFI ER OFF
GO
SET ANSI_NULLS ON
GO
Alter Procedure [dbo].[Fetch_Table_Dat a]
AS
Begin
-- Declare the variables to store the values returned by FETCH.
DECLARE @Table varchar(8000);
declare @cmd varchar (8000);
set @cmd = ''
DECLARE Table_cursor CURSOR FOR
SELECT distinct ProjektTabelle
FROM dbo.T_TProjekte ;
OPEN Table_cursor;
-- Perform the first fetch and store the values in variables.
-- Note: The variables are in the same order as the columns
-- in the SELECT statement.
FETCH NEXT FROM Table_cursor
INTO @Table;
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
-- Concatenate and display the current values in the variables.
if @cmd <> ''
set @cmd = @cmd + ' union '
set @cmd = @cmd + 'Select CNI,CPROJEKT from ' + @Table
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM Table_cursor
INTO @Table
exec(@cmd)
END
CLOSE Table_cursor
DEALLOCATE Table_cursor
END
GO
SET QUOTED_IDENTIFI ER OFF
GO
SET ANSI_NULLS ON
GO
Ho would I go about changing this SP to a Function that RETURNS A list of all Records?
thanks in advance
Jeff
Comment