varsha dodiya

varsha dodiya

  • NA
  • 407
  • 73.8k

extracting values on certain date matching condition

Jul 18 2014 8:07 AM
hey friends.
i want to show (extract) product names , which are near to be expired in WInforms in SQL server 2008 of visual studio 2010
I found dis for one table , but i want to fetch data from two tables in single datagridview.

I have two tables PRO and OPN_STK

in PRO
PId        P_name        P_expdate
1          crocin           1-jan-14      
2          disprin           2-mar-15
3          vicks             2-jan-14


in OPN_STK
P_oe        P_name        P_oexpdate
1            combiflame    1-jan-14      
2             d-cold           2-mar-15
3             Glucose           2-jan-14


i want if today is 18-jul-14  then those product name should be fetched whose exp_date are exactly 6 months before than the date of today(current date of system)


like dis

P_oe        P_name        P_oexpdate

1         combiflame      1-jan-14  
2          vicks             2-jan-14
3         crocin             1-jan-14    


i tried this code

SELECT P_name from OPN_STK where (P_oexpdate < DateADD(month , -6 , Getdate()))


and this query is giving me desired result for 1 table but when i put join to fetch data from both table its only giving me result from one table only

i wrote
  SELECT P_name from OPN_STK,PRO where P_id=P_oe and (P_oexpdate < DateADD(month , -6 , Getdate()))

Help me plz i really need it to be fixed . thanks in advance .

Answers (4)