Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 dynamically pass table to function

Author  Topic 

satishk
Starting Member

39 Posts

Posted - 2006-10-31 : 08:05:22
CREATE FUNCTION testFun(@value varchar(10), @colname varchar(10),@tblName varchar(10))
returns @v table (col1 varchar(10), col2 varchar(10), col3 varchar(10))
AS

begin
if @tblname = 'datatbl' and @colname = 'col1'
insert @v select * from dataTbl where col1 = @value

if @tblname = 'datatbl' and @colname = 'col2'
insert @v select * from dataTbl where col2 = @value

if @tblname = 'datatbl' and @colname = 'col3'
insert @v select * from dataTbl where col3 = @value

if @tblname = 'datatbl2' and @colname = 'col1'
insert @v select * from dataTbl2 where col1 = @value

if @tblname = 'datatbl2' and @colname = 'col2'
insert @v select * from dataTbl2 where col2 = @value

if @tblname = 'datatbl2' and @colname = 'col3'
insert @v select * from dataTbl2 where col3 = @value

return
end

select * from dbo.testFun('a', 'x','dataTbl')
select * from dbo.testFun('a', 'x','dataTbl2'


The above function was written by gentleman Peso.
But I want to call this function in another function so as to return a column
Can this be done?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-31 : 08:16:47
Yes, you can use the result of this function as any other table.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-01 : 02:43:55
Continue here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74267


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -