|
maevr
Posting Yak Master
169 Posts |
Posted - 2010-12-21 : 16:31:06
|
| I need to create a new ID based on the criteria below:myNewID should be based on myType, myYear and a seed number based on how many occurances there is of the specific sort.IF myType is S then the myNewID should start with 'S' then check the myYear to set the next character and then a seed number.myYear < 1960 = 1myYear between 1960 and 1980 = 2myYear > 1980 = 3create table #table1(myOldID varchar(20) not null,myNewID varchar(10) null,myType varchar(1) not null,myYear int not null)insert into #table1(myOldID, myType, myYear) values('1080100', 'S', 1950)insert into #table1(myOldID, myType, myYear) values('4888383', 'S', 1958)insert into #table1(myOldID, myType, myYear) values('1191717', 'S', 1974)insert into #table1(myOldID, myType, myYear) values('1080200', 'L', 1968)insert into #table1(myOldID, myType, myYear) values('1031234', 'L', 1999)insert into #table1(myOldID, myType, myYear) values('1997551', 'F', 2004)insert into #table1(myOldID, myType, myYear) values('2000876', 'F', 2009)insert into #table1(myOldID, myType, myYear) values('1876444', 'F', 1982)Expected output:1080100, S1001, S, 1950)4888383, S1002, S, 1958)1191717, S2001, S, 1974)1080200, L2001, L, 1968)1031234, L3001, L, 1999)1997551, F3001, F, 2004)2000876, F3002, F, 2009)1876444, F3003, F, 1982) |
|