ranjithvenkatesh
Programmer
Database: SQL Server 2000
OS: Windows XP Professional
Tables:
PROJECT: PROJECT_ID - primary key
SCHEDULE: PROJECT_ID - foreign key
STARTDATE - string (yyyymmdd)
Aim: To get the Start Date string from the SCHEDULE table given the PROJECT_ID
Checks: NULL, EXISTS and default value to be returned if not available
Problem: The query takes an average of 700 milliseconds. How do I optimize the code below?
Stored Procedure:
CREATE PROCEDURE StartDate (@key nvarchar(50)) AS
if exists (select SCHEDULE.STARTDATE as StartDate from SCHEDULE, PROJECT
where PROJECT.PROJECT_ID=@key and
SCHEDULE.PROJECT_ID=PROJECT.PROJECT_ID
)
select isnull(SCHEDULE.STARTDATE,20050101) as StartDate from SCHEDULE, PROJECT
where PROJECT.PROJECT_ID=@key and
SCHEDULE.PROJECT_ID=PROJECT.PROJECT_ID
else
select 20050101
GO
OS: Windows XP Professional
Tables:
PROJECT: PROJECT_ID - primary key
SCHEDULE: PROJECT_ID - foreign key
STARTDATE - string (yyyymmdd)
Aim: To get the Start Date string from the SCHEDULE table given the PROJECT_ID
Checks: NULL, EXISTS and default value to be returned if not available
Problem: The query takes an average of 700 milliseconds. How do I optimize the code below?
Stored Procedure:
CREATE PROCEDURE StartDate (@key nvarchar(50)) AS
if exists (select SCHEDULE.STARTDATE as StartDate from SCHEDULE, PROJECT
where PROJECT.PROJECT_ID=@key and
SCHEDULE.PROJECT_ID=PROJECT.PROJECT_ID
)
select isnull(SCHEDULE.STARTDATE,20050101) as StartDate from SCHEDULE, PROJECT
where PROJECT.PROJECT_ID=@key and
SCHEDULE.PROJECT_ID=PROJECT.PROJECT_ID
else
select 20050101
GO