Hi guys, I have this old table that was using a Stored Procedure for querying, but now that table has one new column and the query must use that new column. My problem is: I need to keep querying that old table with the old columns until a date (when the new column was added) and after that date I have to query the new column. My question is: Since a couple of Stored Procedures query that table, I have chosen to create an unique index for the date column and add in the WHERE clause the date until it must search and added an union with the same query but with the new column and also in the WHERE added a date to start searching from there. So there is a better way to accomplish this? Is this way ok? This is an example of what I tried to explain: -- Old Query SELECT DISTINCT ColumnA, ColumnB FROM TableA WHERE ColumnA IS NOT NULL AND MONTH(DateColumn) = @aMONTH AND YEAR(DateColumn) = @aYEAR -- New Query SELECT DISTINCT ColumnA, ColumnB FROM TableA WHERE ColumnA IS NOT NULL AND MONTH(DateColumn) = @aMONTH AND YEAR(DateColumn) = @aYEAR AND TableA.DateColumn <= '08/08/2014' UNION SELECT DISTINCT convert(varchar(50), TableB.NewColumn), ColumnB FROM TableA INNER JOIN TableB ON TableA.NewColumn = TableB.NewColumn WHERE ColumnA IS NOT NULL AND MONTH(DateColumn) = @aMONTH AND YEAR(DateColumn) = @aYEAR AND TableA.DateColumn >= '08/08/2014' Regards, raúl
I've seen a similar approach in the past. It seems reasonable. Looking at the date for the transition, it looks like you will still be using the "old" column, even after the cutoff date if that's what TableA.DateColumn says for that row. You would see a mix of "old" and "new" columns in the same result set. Is that your intent?