Home All Groups Group Topic Archive Search About

Storedprocedure > Table name as parameter

Author
23 Sep 2005 7:39 AM
Hari Krishna
Here i am in confusion to slove my probem. pls help me
Here i am going to develop project backend as Sql server
Here i have a doubt in Storedprocedure. I think u can slove this.  My
problem is  like this

I need to fill Grid with some x table,when i enter into x option then grid
will fill with xtable in sql server, and next when i enter in y option then
grid will with ytable.

Here i have to create 2 procedure for getting data for x,y tables
separately.
But i want to get data with single procedure by giving table name as
parameter. when i send table name as parameter then that procedure will
return that table.

For Ex:

CREATE PROCEDURE [filltab] (@ta varchar)  AS
select * from #ta
GO

Here  i declared ta as varcahr (For table name)
when i pass the table name through ta variable
then select statement should execute like this

select * from [given table name]

But it is working .
so i am requesting pls send  a procedure with tbale name as parameter .

Very thank ful
N.Hari krishna

Here i am waitng for u r reply

Author
23 Sep 2005 7:50 AM
Jens
CREATE PROCEDURE [filltab] (@ta varchar(100))  AS
EXEC('select * from ' +  @ta)
GO

But before you start coding everything in dynamic sql, read
http://www.sommarskog.se/dynamic_sql.html


HTH, jens Suessmeyer.

AddThis Social Bookmark Button