Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004

    Unanswered: Can someone help me with this??

    I have two tables one holds data (#temp) and the other one is a reference table(#temp2). I would like to grab date from #temp table with #temp2 table column value as my data column. If you look at my example below, you should see what I mean

    --my data table
    create table #temp (misc1 varchar(10), misc2 varchar(10) , misc3 varchar(10))
    insert into #temp values ('Manager','NA','Texas')
    insert into #temp values ('VP','EMA','London')

    --my reference table
    create table #temp2 (Property varchar(10), Value varchar(10))
    insert into #temp2 values ('misc1','Title')
    insert into #temp2 values ('misc2','Region')
    insert into #temp2 values ('misc3','Location')

    --my pseudo query, ofcourse this does not work and this is where I need
    misc1 as (select value from #temp2 where property='misc1'),
    misc2 as (select value from #temp2 where property='misc2'),
    misc3 as (select value from #temp2 where property='misc3')
    from #temp2

    --To get the results like below
    Title Region Location
    Manager NA Texas
    VP EMA London
    Thanks to all for helping!!

  2. #2
    Join Date
    Jun 2003
    Provided Answers: 1
    You would have to use a technique called a correlated subquery, where the subqueries in your SELECT clause reference the primary key of the outer table in their WHERE clause.
    And I have to tell you, this is database design (known as an EAV, or Entity Attribute Value schema) is one of the WORST database designs possible. This is extremely inefficient, so I hope you aren't going to be loading a lot of data into it or expecting good performance.
    If it's not practically useful, then it's practically useless.

    blindman "sqlblindman"

Posting Permissions

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