Query to Post Results to View

  • I have a table in a database that has very old and not very relational and I want to create a quick view to show the information in a better way. Let's say that the table has 4 fields : id , child1, child2, child3. I want to create a view from this table that will show two fields : id and child. So, my table currently looks like this:

    id      child1      child2      child3

    1        sam        bob         chris

    and i would like it like this......

    id       child

    1        sam

    1        bob

    1        chris

     

    Can anybody help me? Thanks in advance,

    Bob

  • ALTER      VIEW [dbo].YourView AS

    SELECT [id],Child1 FROM Table1

     

    ******************
    Dinakar Nethi
    Life is short. Enjoy it.
    ******************

  • You'd need a union for each column. ie:

    CREATE VIEW [dbo].[NiceChildren] As,

    SELECT [ID], Child1 FROM [dbo].[Children]

    UNION ALL

    SELECT [ID], Child2 FROM [dbo].[Children]

    UNION ALL

    SELECT [ID], Child3 FROM [dbo].[Children]

    UNION ALL

    SELECT [ID], Child4 FROM [dbo].[Children]

  • thank you Shaunio for the help....works like a charm.

     

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply