I need to get static data from database like countries, cities and e.g. They certainly stored in different tables but thier structure very similar. It is like id and name. I have 15 tables like that, so I write function that gets table name and returns all rows from that table. It is realy easy to make such function on C#/VB.NET. Here is how does it look like as stored procedure:
CREATE PROCEDURE GetIdNameCollection
(
@table_name varchar(256)
)
AS
DECLARE @var as varchar(500)
IF OBJECT_ID(@table_name) IS NULL
RAISERROR('User table or view not found.',16,1)
select @var = 'SELECT * FROM '+@table_name
exec(@var)
GO