Stored Procedure WHERE

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: warway (warway_at_hotmail.com)
Date: 11/03/04


Date: Wed, 3 Nov 2004 12:00:10 -0000

I want to use a store procedure to select records based on a date range but
the date range can be in one of two fields depending on the data in another
field..

So I want to select records with an ETA (@FindDate) within a range
(@StartDate and @EndDate) if the record is an 'Import' (stored in
ServiceDescription), else with an ETS (@FindDate) within the same range.

I get error 156 : Incorrect syntax near word AS

Any pointers in the right direction would be wonderful.

CREATE Procedure dbo.sp_Report1 (@StartDate smalldatetime,@EndDate
smalldatetime,@FindDate smalldatetime)

AS

SELECT *,
 CASE WHEN ServiceDescription = 'Import' THEN ETA AS @FindDate
 ELSE ETS AS @FindDate
 END

FROM dbo.Report1View
WHERE
@FindDate Between @StartDate and @EndDate

return
GO

warway@hotmail.com



Relevant Pages

  • Re: Stored Procedure WHERE
    ... > ELSE ETS ... > END AS @FindDate ... >> I want to use a store procedure to select records based on a date range ... >> smalldatetime,@FindDate smalldatetime) ...
    (microsoft.public.sqlserver.programming)
  • Re: Stored Procedure WHERE
    ... ELSE ETS ... END AS FindDate ... (CASE WHEN ServiceDescription = 'Import' THEN ETA ...
    (microsoft.public.sqlserver.programming)
  • RE: Stored Procedure WHERE
    ... CASE WHEN ServiceDescription = 'Import' THEN ETA ... ELSE ETS ... @FindDate Between @StartDate and @EndDate ... > ServiceDescription), else with an ETS within the same range. ...
    (microsoft.public.sqlserver.programming)