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 2005 Forums
 Transact-SQL (2005)
 @parameter as part of table or column name

Author  Topic 

madmaiden
Starting Member

1 Post

Posted - 2008-01-08 : 08:22:14
Hello

I am new in this forum, so is there are references for my topic just send me the link.
What I am trying to do, is a Stored Procedure under SqlServer2005 where the paramerts should be used as part of the table name.
the select shloud look something like:
SELECT @p1.@p1
FROM @p1,...etc
WHERE @p1.id_@p1=@p2

p1 and p2 are validalid....so let's say i got 1 table named "NAMES"
and it has the columns "NAMES" and "ID_NAMES"
SELECT NAMENS.NAMES
FROM NAMES
WHERE NAMES.ID_NAMES=3

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-08 : 08:28:38
quote:
Originally posted by madmaiden

Hello

I am new in this forum, so is there are references for my topic just send me the link.
What I am trying to do, is a Stored Procedure under SqlServer2005 where the paramerts should be used as part of the table name.
the select shloud look something like:
SELECT @p1.@p1
FROM @p1,...etc
WHERE @p1.id_@p1=@p2

p1 and p2 are validalid....so let's say i got 1 table named "NAMES"
and it has the columns "NAMES" and "ID_NAMES"
SELECT NAMENS.NAMES
FROM NAMES
WHERE NAMES.ID_NAMES=3


You should avoid passing object names as parameter
Make sure you read this fully
www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -