Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: how to retrieve records joining 2 tables between 2 dates??


Message #1 by "kaps" <stradbroke@c...> on Wed, 13 Mar 2002 12:40:21
Helo ppl,



I m having some trouble with just normaly query!!n drives me crazy!!





I AM USING SQL SERVER!!(ITS NOT ACCESS)



i got 2 tables "purchase" & "product"



fields in :



purchase:

purchid,fk_prodid,purchdate,amount,receipt



product: prodid, prodname,price



fk_prodid is  a foreign key to product table..



and i m trying to fetch the records e.g



prodname,puchdate,amount,receipt between 2 particular date selected by 

user!!



i m able to to join the table but when i try to use between for those 2 

dates selected!

it gives me all the records!!



i tried datediff function!!



the easiest was between but didnt work!!



any help out there?



thanx a lot!!



Message #2 by "Ken Schaefer" <ken@a...> on Fri, 15 Mar 2002 09:52:09 +1100
CREATE PROC usp_myProc

    @StartDate    dateTime,
    @EndDate     dateTime

AS

    SELECT
        a.ProdName,
        b.PurchDate,
        b.Amount,
        b.Receipt
    FROM
        Product a
    INNER JOIN
        Purchase b
    ON
        a.ProdID = b.fk_ProdID
    WHERE
        b.PurchDate >= @StartDate
    AND
        b.PurchDate <= @EndDate

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "kaps" <stradbroke@c...>
Subject: [asp_databases] how to retrieve records joining 2 tables between 2
dates??


: i got 2 tables "purchase" & "product"
:
: fields in :
: purchase:
: purchid,fk_prodid,purchdate,amount,receipt
:
: product: prodid, prodname,price
:
: fk_prodid is  a foreign key to product table..
:
: and i m trying to fetch the records e.g
:
: prodname,puchdate,amount,receipt between 2 particular date selected by
: user!!
:
: i m able to to join the table but when i try to use between for those 2
: dates selected!
: it gives me all the records!!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  Return to Index