Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Getting SP results from a table with multiple rows for same ID [modified]

Getting SP results from a table with multiple rows for same ID [modified]

Scheduled Pinned Locked Moved Database
databasehelpquestionsharepointxml
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DeepToot
    wrote on last edited by
    #1

    I have a stored procedure that is used with a Search form we have. Search form has about 15 parameters it can take, all optional. The database is a mess and im stuck working around it so bare with me while I try to explain my issue. There are more issues but want to focus on the Buyer/Seller issue for now. The long and short of my problem is this - the data entry form has fields for { Buyer First Name, Buyer Last Name, Seller First Name, Seller Last Name} These will be inserted into table BuyerSeller (for instance) The schema for this: BuyerSellerID | FirstName | LastName this table is holds both Buyer and Seller information. So what we end up with is: BuyerSellerID | FirstName | LastName 100 | BuyerFirst | BuyerLast 101 | SellerFirst | SellerLast But now the issue comes into play when he created an index lookup table called BuyerSellerInfo that includes: BuyerorSellerInfoID (primary key) | MortgageID | BuyerID | SellerID What the original developer did was put the Buyer information as one record, and the Seller information in another record, each for the same data entry. so we end up with: BuyerorSellerInfoID (primary key) | MortgageID | BuyerID | SellerID 1 | 10 | 1 | NULL 2 | 10 | NULL | 2 So now with my question - how can I create a stored procedure that will produce results in the same row. I am getting duplicates for each row (which I know the way it is setup I would). But is there a way in my Stored Procedure to have the output look like: BuyerorSellerInfoID (primary key) | MortgageID | BuyerID | SellerID 1 | 10 | 1 | 2
    Hope this made sense, question me if it does not. The formatting on my code tags didn't go so well the "|" is seperator for columns. The database is SQL 2000 as well. Thanks.

    modified on Friday, March 12, 2010 4:02 PM

    L R 2 Replies Last reply
    0
    • D DeepToot

      I have a stored procedure that is used with a Search form we have. Search form has about 15 parameters it can take, all optional. The database is a mess and im stuck working around it so bare with me while I try to explain my issue. There are more issues but want to focus on the Buyer/Seller issue for now. The long and short of my problem is this - the data entry form has fields for { Buyer First Name, Buyer Last Name, Seller First Name, Seller Last Name} These will be inserted into table BuyerSeller (for instance) The schema for this: BuyerSellerID | FirstName | LastName this table is holds both Buyer and Seller information. So what we end up with is: BuyerSellerID | FirstName | LastName 100 | BuyerFirst | BuyerLast 101 | SellerFirst | SellerLast But now the issue comes into play when he created an index lookup table called BuyerSellerInfo that includes: BuyerorSellerInfoID (primary key) | MortgageID | BuyerID | SellerID What the original developer did was put the Buyer information as one record, and the Seller information in another record, each for the same data entry. so we end up with: BuyerorSellerInfoID (primary key) | MortgageID | BuyerID | SellerID 1 | 10 | 1 | NULL 2 | 10 | NULL | 2 So now with my question - how can I create a stored procedure that will produce results in the same row. I am getting duplicates for each row (which I know the way it is setup I would). But is there a way in my Stored Procedure to have the output look like: BuyerorSellerInfoID (primary key) | MortgageID | BuyerID | SellerID 1 | 10 | 1 | 2
      Hope this made sense, question me if it does not. The formatting on my code tags didn't go so well the "|" is seperator for columns. The database is SQL 2000 as well. Thanks.

      modified on Friday, March 12, 2010 4:02 PM

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      I'm no DB expert, however I would search along these lines:

      SELECT * FROM BuyersSellers AS b JOIN BuyersSellers AS s WHERE b.MortgageID=s.MortgageID AND b.BuyerID IS NOT NULL AND s.SellerID IS NOT NULL

      :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


      D 1 Reply Last reply
      0
      • L Luc Pattyn

        I'm no DB expert, however I would search along these lines:

        SELECT * FROM BuyersSellers AS b JOIN BuyersSellers AS s WHERE b.MortgageID=s.MortgageID AND b.BuyerID IS NOT NULL AND s.SellerID IS NOT NULL

        :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


        D Offline
        D Offline
        DeepToot
        wrote on last edited by
        #3

        Thank you for the quick reply. I will give it a test and give feedback or mark as answer.

        1 Reply Last reply
        0
        • D DeepToot

          I have a stored procedure that is used with a Search form we have. Search form has about 15 parameters it can take, all optional. The database is a mess and im stuck working around it so bare with me while I try to explain my issue. There are more issues but want to focus on the Buyer/Seller issue for now. The long and short of my problem is this - the data entry form has fields for { Buyer First Name, Buyer Last Name, Seller First Name, Seller Last Name} These will be inserted into table BuyerSeller (for instance) The schema for this: BuyerSellerID | FirstName | LastName this table is holds both Buyer and Seller information. So what we end up with is: BuyerSellerID | FirstName | LastName 100 | BuyerFirst | BuyerLast 101 | SellerFirst | SellerLast But now the issue comes into play when he created an index lookup table called BuyerSellerInfo that includes: BuyerorSellerInfoID (primary key) | MortgageID | BuyerID | SellerID What the original developer did was put the Buyer information as one record, and the Seller information in another record, each for the same data entry. so we end up with: BuyerorSellerInfoID (primary key) | MortgageID | BuyerID | SellerID 1 | 10 | 1 | NULL 2 | 10 | NULL | 2 So now with my question - how can I create a stored procedure that will produce results in the same row. I am getting duplicates for each row (which I know the way it is setup I would). But is there a way in my Stored Procedure to have the output look like: BuyerorSellerInfoID (primary key) | MortgageID | BuyerID | SellerID 1 | 10 | 1 | 2
          Hope this made sense, question me if it does not. The formatting on my code tags didn't go so well the "|" is seperator for columns. The database is SQL 2000 as well. Thanks.

          modified on Friday, March 12, 2010 4:02 PM

          R Offline
          R Offline
          riced
          wrote on last edited by
          #4

          Swelborn wrote:

          so bare with me while I try to explain

          Have you been reading The Nudist On The Nightshift? :-D

          Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

          D 1 Reply Last reply
          0
          • R riced

            Swelborn wrote:

            so bare with me while I try to explain

            Have you been reading The Nudist On The Nightshift? :-D

            Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

            D Offline
            D Offline
            DeepToot
            wrote on last edited by
            #5

            hehe can't say that I have.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups