Newbie SQL question

Last post 06-06-2008, 10:36 AM by ahmjt. 1 replies.
Sort Posts: Previous Next
  •  06-06-2008, 9:53 AM Post number 59013

    Newbie SQL question

    Hi,

    I'm looking at trying to manipulate some data in one table and add it to another. So my question is what is the best way to achieve this?

    Here's the scenario:

    Table has two columns A and B, where there can be multiple distinct values in column B per each distinct value in column A. e.g.

    A         B
    1         i
    1         ii
    1         iii
    2         I
    2         II

    I want to be able to combine this data into a new table in one column in the following format:

    i (1)
    ii (1)
    iii (1)
    I (2)
    II (2)

    Any help will be gratefully received.

    Thanks

    Mosser212

  •  06-06-2008, 10:36 AM Post number 59017 in reply to post number 59013

    • ahmjt is not online. Last active: 06-10-2008, 2:56 AM ahmjt
    • Not Ranked
    • Joined on 06-06-2008
    • Level 1: Deep thought

    Re: Newbie SQL question

    Hi
    Can you not use concatenate the two columns into one column.  Something like the following:

    declare @t1 table
    (
    A varchar(5)
    ,B varchar(5)
    )

    declare @t2 table
    (
    AB varchar(10)
    )

    insert into @t1(A, B)values('1','i')
    insert into @t1(A, B)values('1','ii')
    insert into @t1(A, B)values('1','iii')
    insert into @t1(A, B)values('2','L')
    insert into @t1(A, B)values('2','LL')

    insert into @t2 (AB)
    select B + '(' + A + ')' from @t1
View as RSS news feed in XML