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. help setting up matrix cross-refrence query [modified]

help setting up matrix cross-refrence query [modified]

Scheduled Pinned Locked Moved Database
databasehtmlhelptutorialquestion
6 Posts 5 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.
  • E Offline
    E Offline
    empulse
    wrote on last edited by
    #1

    I am not totally sure what the proper terminology for this structure is but the situation is: I have three tables Table One: Category ------------------- CatID (int, index) Category (varchar) Example Values(fruit, vegetable, mineral, language. etc) Table Two: Objects ---------------------- ObjectID (int, index) Parent_Category (int, Foreign Key to CatID) ObjectName (varchar) example Values (Apples, Brocolli, Copper, etc) table Three: Content ------------------------ ContentID (primary key) CatID (FK to table Category) ObjectID (Fk to table Objects) ...OtherContent... I need to construct a select statement that produces something similar to the following format

           Fruit   Vegetable  Mineral  Language 
    

    Apple X
    Bananna X
    French X
    Brocolli X
    Cherry X
    Cabbage X
    Iron X

    Idealy, I would like to have the ContentID of the correspondig record from the third table (Content) displayed in place of each "X". The goal is to generate an HTML page with an HREF at each "X" that links to a page that retrieves the specific record from the Content table. Any suggestions?

    modified on Monday, August 18, 2008 2:05 PM

    D T W M 4 Replies Last reply
    0
    • E empulse

      I am not totally sure what the proper terminology for this structure is but the situation is: I have three tables Table One: Category ------------------- CatID (int, index) Category (varchar) Example Values(fruit, vegetable, mineral, language. etc) Table Two: Objects ---------------------- ObjectID (int, index) Parent_Category (int, Foreign Key to CatID) ObjectName (varchar) example Values (Apples, Brocolli, Copper, etc) table Three: Content ------------------------ ContentID (primary key) CatID (FK to table Category) ObjectID (Fk to table Objects) ...OtherContent... I need to construct a select statement that produces something similar to the following format

             Fruit   Vegetable  Mineral  Language 
      

      Apple X
      Bananna X
      French X
      Brocolli X
      Cherry X
      Cabbage X
      Iron X

      Idealy, I would like to have the ContentID of the correspondig record from the third table (Content) displayed in place of each "X". The goal is to generate an HTML page with an HREF at each "X" that links to a page that retrieves the specific record from the Content table. Any suggestions?

      modified on Monday, August 18, 2008 2:05 PM

      D Offline
      D Offline
      DerekFL
      wrote on last edited by
      #2

      Why no have a category id in the object table with foreign key to category table? Seems like you have a cross ref table which is only needed in a one to many or many to many relationship. Can an object have 2 categories?

      E 1 Reply Last reply
      0
      • D DerekFL

        Why no have a category id in the object table with foreign key to category table? Seems like you have a cross ref table which is only needed in a one to many or many to many relationship. Can an object have 2 categories?

        E Offline
        E Offline
        empulse
        wrote on last edited by
        #3

        There is a foreign key in the Objects table to the Category Table. The example here is a simplified version of a customer requirement. The real data is actually some obscure industrial materials, but the structure I need is what is illustrated. The output will actually be a web page with intersecting points (represented by the 'X's) Each intersection of material and category would be unique. A "Content" Record will have only one "Category" and One "Object."

        1 Reply Last reply
        0
        • E empulse

          I am not totally sure what the proper terminology for this structure is but the situation is: I have three tables Table One: Category ------------------- CatID (int, index) Category (varchar) Example Values(fruit, vegetable, mineral, language. etc) Table Two: Objects ---------------------- ObjectID (int, index) Parent_Category (int, Foreign Key to CatID) ObjectName (varchar) example Values (Apples, Brocolli, Copper, etc) table Three: Content ------------------------ ContentID (primary key) CatID (FK to table Category) ObjectID (Fk to table Objects) ...OtherContent... I need to construct a select statement that produces something similar to the following format

                 Fruit   Vegetable  Mineral  Language 
          

          Apple X
          Bananna X
          French X
          Brocolli X
          Cherry X
          Cabbage X
          Iron X

          Idealy, I would like to have the ContentID of the correspondig record from the third table (Content) displayed in place of each "X". The goal is to generate an HTML page with an HREF at each "X" that links to a page that retrieves the specific record from the Content table. Any suggestions?

          modified on Monday, August 18, 2008 2:05 PM

          T Offline
          T Offline
          Tripathi Swati
          wrote on last edited by
          #4

          first take Category table in @table or in #table bcoz no of colmns depends upon ur no of rows in category table. then join it with content table - > object table & use switch case for ur specified format.

          1 Reply Last reply
          0
          • E empulse

            I am not totally sure what the proper terminology for this structure is but the situation is: I have three tables Table One: Category ------------------- CatID (int, index) Category (varchar) Example Values(fruit, vegetable, mineral, language. etc) Table Two: Objects ---------------------- ObjectID (int, index) Parent_Category (int, Foreign Key to CatID) ObjectName (varchar) example Values (Apples, Brocolli, Copper, etc) table Three: Content ------------------------ ContentID (primary key) CatID (FK to table Category) ObjectID (Fk to table Objects) ...OtherContent... I need to construct a select statement that produces something similar to the following format

                   Fruit   Vegetable  Mineral  Language 
            

            Apple X
            Bananna X
            French X
            Brocolli X
            Cherry X
            Cabbage X
            Iron X

            Idealy, I would like to have the ContentID of the correspondig record from the third table (Content) displayed in place of each "X". The goal is to generate an HTML page with an HREF at each "X" that links to a page that retrieves the specific record from the Content table. Any suggestions?

            modified on Monday, August 18, 2008 2:05 PM

            W Offline
            W Offline
            Wendelius
            wrote on last edited by
            #5

            Don't know if this is an option for you but one possibility (which could be easy) is to create a stored procedure in order to return correct result set. Stored procedure could return a table type or a cursor (depending on the needs). This way you would have the full power of T-SQL to use and it would be easier to break the logic in to pieces. Another way (haven't tested it though) could be using pivoting and correlated subqueries. Mika

            1 Reply Last reply
            0
            • E empulse

              I am not totally sure what the proper terminology for this structure is but the situation is: I have three tables Table One: Category ------------------- CatID (int, index) Category (varchar) Example Values(fruit, vegetable, mineral, language. etc) Table Two: Objects ---------------------- ObjectID (int, index) Parent_Category (int, Foreign Key to CatID) ObjectName (varchar) example Values (Apples, Brocolli, Copper, etc) table Three: Content ------------------------ ContentID (primary key) CatID (FK to table Category) ObjectID (Fk to table Objects) ...OtherContent... I need to construct a select statement that produces something similar to the following format

                     Fruit   Vegetable  Mineral  Language 
              

              Apple X
              Bananna X
              French X
              Brocolli X
              Cherry X
              Cabbage X
              Iron X

              Idealy, I would like to have the ContentID of the correspondig record from the third table (Content) displayed in place of each "X". The goal is to generate an HTML page with an HREF at each "X" that links to a page that retrieves the specific record from the Content table. Any suggestions?

              modified on Monday, August 18, 2008 2:05 PM

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              look into Pivot queries (presuming SQL 2005)

              Never underestimate the power of human stupidity RAH

              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