| Author |
Topic |
|
Sonu619
Posting Yak Master
202 Posts |
Posted - 2011-09-22 : 12:00:11
|
| Hi guys, Here is my table structureID,FNAME, LNAME, CODE1,JIM,SMITH,BASE2,CARLOS,B,OUT1,CHRIS,UR,BASE2,NOR,SLI,QUIMy requirement is or I want end result like listed belowID,FNAME,LNAME,CODE1,JIM,SMITH,BASE2,CARLOS,B,OUT1-A,CHRIS,UR,BASE2,NOR,SLI,QUIAnd I am using this query;WITH cte1 AS ( SELECT ID, ROW_NUMBER() OVER (PARTITION BY ID ORDER BY (SELECT NULL)) - 1 AS rn FROM Table_Name )update cte1 set ID = ID + CASE WHEN rn > 0 THEN + CHAR(ASCII('A')+rn-1) ELSE '' END After I run above query giving me this resultID,FNAME,LNAME,CODE1,JIM,SMITH,BASE2,CARLOS,B,OUT1-A,CHRIS,UR,BASE2-A,NOR,SLI,QUINote:- But I want to implement this query on where Code = ‘BASE. I tried to use WHERE clause here and there but no luck, Any advice would be big help. Thanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-22 : 12:05:03
|
| so if there's one more instance you append B,C etc?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Sonu619
Posting Yak Master
202 Posts |
Posted - 2011-09-22 : 12:09:31
|
| Want to give you update, I got it, Below is the syntax, ;WITH cte1 AS (SELECT ID, ROW_NUMBER() OVER (PARTITION BY ID ORDER BY (SELECT NULL)) - 1 AS rnFROM Table_Name Where CODE = 'BASE')update cte1 set ID = ID + CASE WHEN rn > 0 THEN + CHAR(ASCII('A')+rn-1) ELSE '' END Thanks. |
 |
|
|
|
|
|