September 9, 2014 at 3:09 pm
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
FROMTableA
WHEREColumnA 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
FROMTableA INNER JOIN TableB ON TableA.NewColumn = TableB.NewColumn
WHEREColumnA IS NOT NULL AND MONTH(DateColumn) = @aMONTH AND YEAR(DateColumn) = @aYEAR
AND TableA.DateColumn >= '08/08/2014'
Regards,
raúl
Viewing 0 posts
You must be logged in to reply to this topic. Login to reply