Link to home
Start Free TrialLog in
Avatar of CalmSoul
CalmSoulFlag for United States of America

asked on

T-SQL - how multiple tables with wild card?

Hello All:

I am using SQL server 2008 R2, how can I query multiple table using a wild card for example ?

Select * from TAB_*

I have 500 tables like this

TAB_09082013
TAB_08072012
etc...

Please let me know
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

Because you need to pass the table name as parameter and views don't take parameter, you need to use a table valued function like:

Select * From fnReadDataFromTable('TAB_09082013');

Or, just use something like in below without a function call:

DECLARE @tablename AS NVARCHAR(261) = N'TAB_09082013';
EXECUTE(N'SELECT * FROM ' + @tablename);
SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CalmSoul

ASKER

@deepakChauhan - it working but I want merged results as well...
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
CalmSoul, do you still need help with this question?