May 21, 2008 at 6:02 am
I have some tables that have prefixes like WRT_(WRT_01, WRT_02, WRT_03). I need help in how to get data from the tables that are for example like 'WRT_%' and are in a specific date range (all the tables have the same columns including the date)
Is this possible? Or a workaround?
Thanks
May 21, 2008 at 6:56 am
you can create the SQL statement as following
DECLARE @sql VARCHAR(MAX)
SET @sql = ''
SELECT @sql = @sql +'SELECT * FROM [' + name + '] ' + char(13) + 'UNION '
FROM sys.objects
WHERE TYPE = 'U'
AND Name Like 'WRT_%'
SET @sql = left(@SQL,len(@SQL) - 7)
PRINT @sql
EXEC (@SQL)
You can put this into a Stored Proc to get the results adhoc
w.lengenfelder
May 21, 2008 at 7:09 pm
I'm getting "Invalid length parameter passed to the SUBSTRING function.", also how would this be put into a stored procedure?
Thanks
May 21, 2008 at 8:00 pm
I do have to ask the stupid question... you are running the code from the database that has the WRT_% tables in it, aren't you?
--Jeff Moden
Change is inevitable... Change for the better is not.
May 22, 2008 at 6:12 am
Yes I have tables like 'WRT_%', and I think I solved the left length problem by storing it in a variable.
May 22, 2008 at 6:39 pm
Cool... if you get the chance, can you post your solution? I'm sure lot's of folks would like to see it.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply