-------------------------------------/* Create Tempory table */----------------------------------------------
--drop table #stack
Create table #stack
(
info1 varchar(786),
trowguid varchar(786)
)
go
-------------------------------------/* End Tempory table */----------------------------------------------
-------------------------------------/* Populate stack */----------------------------------------------
insert into #stack
select info1,rowguid from tablename
where col.tablename = 'C5BE365C-186D-11D5-B6F6-0002A52B4D33'
order by info1
go
-------------------------------------/* end population */----------------------------------------------
-------------------------------------initialise Variables----------------------------------------------
declare
@index int,
@maxindex int,
@Vinfo1 varchar(786),
@Vtrowguid varchar(786),
@len varchar(786),
@myvalue varchar(786),
@p1 varchar(5),
@p2 varchar(5),
@newstring varchar(50)
--Find rowcount for loop--
select @maxindex = count(*) from #stack
--End rowcount for loop--
set @index = 1
-------------------------------------END initialise Variables----------------------------------------------
-------------------------------------Start transformation-------------------------------------------------
while @index < @maxindex
begin
select top 1 @Vinfo1 = info1 from #stack
select top 1 @Vtrowguid = trowguid from #stack
GOTO check_for_Null
delete from #stack where trowguid = @Vtrowguid
end
--add code to delete to top layer of stack .. ---
--- HERE ----
check_for_Null:
if @vinfo1 is null
begin
set @vinfo1 = ''
goto Update_row
end
else
goto check_len
check_len:
set @len = len(@vinfo1)
if @len <= 3
begin
set @vinfo1 = ''
goto Update_row
end
else
goto check_substring
check_substring:
--check for len of first 2 letter/words and then check to see if it patindex "/"
select @myvalue = substring(@vinfo1,patindex('%/%',@vinfo1)-4,4)
set @len = len(@myvalue)
if @len=2
begin
goto transform_data
end
else if @len=4
begin
goto update_row
end
else if @len=0
begin
goto trashCan
end
transform_data:
set @vinfo1 = '04/2004'
select @p1 = substring(@vinfo1,patindex('%/%',@vinfo1)-4,4)
select @p2 = substring(@vinfo1,patindex('%/%',@vinfo1)+1,4)
set @newstring = @p2 + '/' + @p1
set @vinfo1 = @newstring
goto update_row
select @vinfo1
update_row:
update tablename set info1 = @vinfo1
where col.tablename = 'C5BE365C-186D-11D5-B6F6-0002A52B4D33' and
rowguid = @Vtrowguid
trashCan:
print ' trash can'