I have an existing (working) stored procedure that I need to modify. The basics of the SP are:
CREATE PRODEDURE dbo.myProcedure
@dateFrom datetime,
@dateTo datetime
CREATE TABLE #myTempTable
DECLARE @currentDate datetime
SET @currentDate = getdate()
If (left(@dateFrom,11) != left(@currentDate,11))
/* If1: dateFrom is not the current date */
BEGIN
Insert into #myTempTable
SELECT statment from local db1
END
If (left(@dateTo,11) = left(@currentDate,11))
/* If2: dateTo is the currentDate */
BEGIN
Insert into #myTempTable
SELECT statment from linked server database
END
INSERT into #myTempTable
SELECT statement from local db2
SELECT *
FROM #myTempTable
ORDER BY Date ASC
GO
(All date rows that are returned are between @dateFrom and @dateTo due to the select queries)
The revision that I wish to make to this SP is:
If the first select statement (ie. in If1) places a row for the Current Date into the temp table, then I don't want the second select statement (ie. If2) to be executed.
I am unsure of the syntax for this. I don't belive the solutions I have been attempting (further SELECT statements etc) are very efficient.
Thanks for your help. If any further clarifications of the problem are necessary, I will respond ASAP. If anyone knows of any links I should follow to find an answer for myself, please post them!
Thank you,
Earth
CREATE PRODEDURE dbo.myProcedure
@dateFrom datetime,
@dateTo datetime
CREATE TABLE #myTempTable
DECLARE @currentDate datetime
SET @currentDate = getdate()
If (left(@dateFrom,11) != left(@currentDate,11))
/* If1: dateFrom is not the current date */
BEGIN
Insert into #myTempTable
SELECT statment from local db1
END
If (left(@dateTo,11) = left(@currentDate,11))
/* If2: dateTo is the currentDate */
BEGIN
Insert into #myTempTable
SELECT statment from linked server database
END
INSERT into #myTempTable
SELECT statement from local db2
SELECT *
FROM #myTempTable
ORDER BY Date ASC
GO
(All date rows that are returned are between @dateFrom and @dateTo due to the select queries)
The revision that I wish to make to this SP is:
If the first select statement (ie. in If1) places a row for the Current Date into the temp table, then I don't want the second select statement (ie. If2) to be executed.
I am unsure of the syntax for this. I don't belive the solutions I have been attempting (further SELECT statements etc) are very efficient.
Thanks for your help. If any further clarifications of the problem are necessary, I will respond ASAP. If anyone knows of any links I should follow to find an answer for myself, please post them!
Thank you,
Earth