Results 1 to 2 of 2

Thread: SQL Query

  1. #1
    Join Date
    Dec 2010
    Posts
    1

    Unanswered: SQL Query

    i have two tables with below structure

    1)Requested Product

    product_code product_name

    12 alcor

    13 vinegar

    2)Available stock

    product_code product_name available_qty branch_code batch_no

    12 alcor 19000 br_12 batch1

    13 vinegar 30000 br_12 batch2

    12 alcor 100000 br_13 batch3

    13 vinegar 34000 br_13 batch4

    12 alcor 1000 br_12 batch5

    13 vinegar 0 br_12 batch6

    12 alcor 0 br_13 batch7

    13 vinegar 0 br_13 batch8

    i want to fetch all the branch_code having all the products in the Requested Product table ..


    the number of products in Requested Product table may change dynamically..
    i am passing product code from a single parameter through a stored procedure ....
    how to split the parameter inside SP and create filter condition like

    "select 1,2,3 from stock where product_code='p1' and product_code='p2' and product_code='p3'................."

    no of p1, p2,p3 are dynamic.it may vary.

    its urgent anybody can help me out?

    thanks in advance
    subhasis

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT branch_code
      FROM stock 
    GROUP
        BY branch_code
    HAVING COUNT(DISTINCT product_code) =
           ( SELECT COUNT(*) 
               FROM products )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •