My company has a SQL database that contains many tables - a different table for each client. There is one table that is used to identify the tables.
I wrote this query and one for each client and now want to change it to adapt to the tables listed.
select VancouverIsland.id, postdateid, quarkfilename, isrendered, date_posted, category, categoryid,ropadid, convert(varchar(10),postDate,101) as postDate,categoryname, categorytable, newspaperids
join prodSQL1.Prod_Admin.dbo.postDates as p on p.id = VancouverIsland.postDateID
join prodSQL1.Prod_Admin.dbo.categories as cat on cat.ID = p.CategoryID
where postdate between @StartDate and @EndDate
and IsRendered <> 2
The table - VancouverIsland is identified in a table called Categories in a field called 'CategoryTable'.
So, do I something like this?
Declare @tablename string
Set @table name = dbo.Categories.CategoryTable
select @tablename.id, postdateid...