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)
 Getting table name dynamically for query

Author  Topic 

thiyait
Yak Posting Veteran

70 Posts

Posted - 2005-10-17 : 02:59:11
I need to get the table name from the user defined function for the query.how do i build the query

Here is my procedure and function.
create procedure dbo.GetVendors
@controlID int
as
select * from <Dynamic tablename>--here i need to get dynamically from the function
GO


Function:
CREATE FUNCTION dbo.GetTable(@controlID integer)
RETURNS varchar(25) AS
BEGIN
Declare @return varchar(25)
select @return=Table_Used from profile_collection Where controlID=@controlID
return @return
END

Thanks in advance

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-10-17 : 03:10:25
Are you talking about somthing like this ..

create procedure dbo.GetVendors
@controlID int
as
Exec('select * from ' + Dbo.GetTable(@ContolID))
GO

Complicated things can be done by simple thinking
Go to Top of Page
   

- Advertisement -