Help with Query

  • I need a query where a record has to have the value CardOrKey="Card" or else no records will be returned. As it stands this query returns all records if I leave my parameters as null. Any help would be greatly apprecaited.

    SELECT * FROM [dbo].[tblReportData]

    WHERE (CardORKey="Card")

    AND (LastName = @LastName OR @LastName IS NULL)

    AND (Date >= @StartDate OR @StartDate IS NULL)

    AND (Date < dateadd(dd,1,@EndDate) OR @EndDate IS NULL)

    AND( Department = @Department OR @Department IS NULL)

  • Try this:

    SELECT * FROM [dbo].[tblReportData]

    WHERE (CardORKey='Card')

    AND (LastName = @LastName OR @LastName IS NULL)

    AND (Date >= @StartDate OR @StartDate IS NULL)

    AND (Date < dateadd(dd,1,@EndDate) OR @EndDate IS NULL)

    AND( Department = @Department OR @Department IS NULL)

  • Thanks a Bunch. I appreciate your help.

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

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