Results 1 to 5 of 5

Thread: Easy question

  1. #1
    Join Date
    Nov 2003
    Location
    Romania
    Posts
    70

    Unanswered: Easy question

    Original Table

    Col_1 ---Col_2
    DE
    DE
    XB
    DE
    C
    XB
    D
    XB

    I want to obtain this

    Col_1 --Col_2
    DE----------1
    DE----------1
    XB----------2
    DE----------1
    C-----------3
    XB----------2
    D ----------4
    XB----------2

    or this

    Col_1 ----Col_2
    DE---------- 1
    XB-----------2
    C------------3
    D------------4

    Is possible without use cursors ?
    Last edited by Ovidiu; 04-06-04 at 05:51.

  2. #2
    Join Date
    Mar 2004
    Posts
    80

    Re: Easy question

    Originally posted by Ovidiu
    Original Table

    Col_1 ---Col_2
    DE
    DE
    XB
    DE
    C
    XB
    D
    XB

    I want to obtain this

    Col_1 --Col_2
    DE----------1
    DE----------1
    XB----------2
    DE----------1
    C-----------3
    XB----------2
    D ----------4
    XB----------2

    or this

    Col_1 ----Col_2
    DE---------- 1
    XB-----------2
    C------------3
    D------------4

    Is possible without use cursors ?
    on what basis u r trying to assign col_2 values?
    is it just any sequence ?

  3. #3
    Join Date
    Nov 2003
    Location
    Romania
    Posts
    70
    I sort the table .... ORDER BY col_1 (in reality more that one column)
    The col_2 is empty / Null and I want to update the col_2 with this value: 1, 2, 3 ,4 ..........

  4. #4
    Join Date
    Mar 2004
    Posts
    80
    Originally posted by Ovidiu
    I sort the table .... ORDER BY col_1 (in reality more that one column)
    The col_2 is empty / Null and I want to update the col_2 with this value: 1, 2, 3 ,4 ..........
    Code:
    declare table @Temp(col_1  type,col_2 int identity(1,1))
    
    insert @temp select distinct col_1 from originaltable order by col_1
    
    update originaltable set col_2=t.col_2 from originaltable as ot join @Temp as t on ot.col_1=t.col_1

  5. #5
    Join Date
    Nov 2003
    Location
    Romania
    Posts
    70
    Thanks

Posting Permissions

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