Amount range in stored procedure

  • Create PROCEDURE [dbo].[procCityWiseListofPledgeSelect]

    @EVENTCODEID INT,

    @FROMEVENTDATE DATE,

    @TOEVENTDATE DATE,

    @FROMAMOUNT MONEY,

    @TOAMOUNT MONEY

    AS

    BEGIN

    SET NOCOUNT ON;

    SET @FROMEVENTDATE = NULLIF(@FROMEVENTDATE,'1753-01-01 00:00:00.000')

    SET @TOEVENTDATE = NULLIF(@TOEVENTDATE,'1753-01-01 00:00:00.000')

    IF @TOAMOUNT IS NULL OR @TOAMOUNT = ''

    SET @TOAMOUNT = @FROMAMOUNT

    SELECT C.CITYNAME AS CITY

    ,PLEDGE_ID

    ,TOTALPLEDGEDAMOUNT

    ,TOTALPLEDGEDAMOUNTUSD

    ,P.PLEDGEDDATE AS EVENTDATE

    ,P.EVENTCODE_ID

    FROM EVENTSCHEDULE AS ES

    RIGHT JOIN EVENTBATCH AS EB ON ES.EVENTSCHEDULE_ID = EB.EVENTSCHEDULE_ID

    LEFT JOIN PLEDGE AS P ON EB.EVENTBATCH_ID = P.EVENTBATCH_ID

    LEFT OUTER JOIN PARTNERS AS PA ON P.PARTNER_ID=PA.PARTNER_ID

    WHERE 1=1

    AND ((@EVENTCODEID IS NULL) OR (P.EVENTCODE_ID = @EVENTCODEID))

    AND ((@FROMEVENTDATE IS NULL) OR (P.PLEDGEDDATE BETWEEN @FROMEVENTDATE AND @TOEVENTDATE))

    AND ((@FROMAMOUNT IS NULL) OR (P.TOTALPLEDGEDAMOUNT BETWEEN @FROMAMOUNT AND @TOAMOUNT))

    END

    instead of this :

    AND ((@FROMAMOUNT IS NULL) OR (P.TOTALPLEDGEDAMOUNT BETWEEN @FROMAMOUNT AND @TOAMOUNT))

    how to pass the amount range like

    and p.totalpledgedamount >= 1000 and p.totalpledgedamount <= 10000

    OR

    and p.totalpledgedamount > 1000 and p.totalpledgedamount <= 10000

    OR

    and p.totalpledgedamount >= 1000

    That is I need to pass amount range and also the >=, <=, >, < ... etc.

  • Hi ,

    please see this link

    http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/



    Clear Sky SQL
    My Blog[/url]

  • (http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

    ) I think this link should answer all the queries!!..

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply