Search code examples
asp.netsql-serverentity-attribute-value

Efficient SQL procedure to get data from name value pair table into DataSet?


Using SQL Server, have a name value pair table. Each row is basically userid, contentid, sectionid, parameter, value. So there is data I want to display in a table such as user information. Each bit of information is in it's own row, sow how do I get it into a DataSet for use in a Repeater? Can I somehow merge the rows into one? So I can get multiple parameter/value pairs on one row?

so like...

two rows for user 32:

(param / value)
fname / Bob
lname / Smith

displayed on one row in a repeater like this:

Bob Smith

Any ideas? Oh yeah and the reason it is in the name/value pair format is to adhere to a required standard.


Solution

  • Maybe something like...

    SELECT fff.firstname, lll.lastname
    FROM (
      SELECT ff.value AS firstname
      FROM PairTable AS ff
      WHERE ff.param = 'fname'
        AND ff.userId = 32
    ) fff, (
      SELECT ll.value AS lastname
      FROM PairTable AS ll
      WHERE ll.param = 'lname'
        AND ll.userId = 32
    ) lll