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)
 Creating view from multiple tables dynamicaly

Author  Topic 

neeraj1401
Starting Member

36 Posts

Posted - 2009-01-14 : 00:08:08
Hi All ,

I wanted to created a procedure which will create a view or table having the data from multiple tables. I have the following constrain
1. Tables name will changes but structure will remain the same.
2. Number of tables is not confirmed it will change on daily basis.

structure of all the tables will remain same.

Please advice.

thanks in advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-14 : 00:17:45
i dont think this is a good approach. you need to use dynamic sql for this which can cause sql injection attacks.Why does your tables change dynamically?
Go to Top of Page

neeraj1401
Starting Member

36 Posts

Posted - 2009-01-14 : 02:44:34
Hi,

Thanks for reply

I'm geeting the data from third party software, which is dumping the data in sql tables on daily basis.I have to fecth some common field from all that tables. whenever they exporting data it create new tables. so I'm looking for a procedure which will automatically picked the common field from all tables.

looking forward for your reponse.

cheer's
Neeraj

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-14 : 02:55:34
quote:
Originally posted by neeraj1401

Hi,

Thanks for reply

I'm geeting the data from third party software, which is dumping the data in sql tables on daily basis.I have to fecth some common field from all that tables. whenever they exporting data it create new tables. so I'm looking for a procedure which will automatically picked the common field from all tables.

looking forward for your reponse.

cheer's
Neeraj




if you're fields will be same then you can use undocumented stored procedure sp_Msforeachtable to loop through tables and do something on those columns
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-14 : 02:56:27
Also see this for example usage:-
http://www.databasejournal.com/features/mssql/article.php/3441031/SQL-Server-Undocumented-Stored-Procedures-spMSforeachtable-and-spMSforeachdb.htm
Go to Top of Page
   

- Advertisement -