SQL Server Performance

Converting a single row data to multiple columns

Discussion in 'SQL Server 2005 General Developer Questions' started by Frontier, Mar 20, 2010.

  1. Frontier New Member

    Hello,
    This is my first post on this nice forum, so please be gentle [:)]
    I have a table which looks like this:
    Table: Main
    ID Name Probe
    -----------------------------------
    1 xxx |1234|567|3456|
    2 yyy |234|3456|7654|3890|3421|
    3 zzz |4566|2|4632|5678|
    The data in the Probe field represent rows in another table (with ID's of 1234, 567, 3456 and so on - let's call it ProbeTbl).
    Table: ProbeTbl
    ID Name
    -------------------------------
    2 Haha!
    1234 So you think
    567 you can do this
    3456 easily!
    What I am trying to do is to write a SELECT query in order to join the two tables and fetch the Probe data from the ProbeTbl aswell.
    The idea is to query table Main (e.g Main.ID=1) and get also 'So you think', 'you can do this', 'easily'.
    The problem is that each Main.Probe field is variable and I don't know how to turn one Probe record into multiple rows.
    Any ideas how this can be done?
    Many thanks in advance.
  2. Adriaan New Member

    Well, I just hope that this is a classroom excercise. If you ever run into this in a production database, you know it will only ever give you massive headaches because someone decided to go against the very core of database design - normalization.
  3. Frontier New Member

    Thank you for the quick and prompt reply. It's a classroom exercise.
    Unfortunately, I'm stuck on this :(
  4. Adriaan New Member

    Think writing code with a lot of string functions ...

Share This Page