Hi, I have written a Stored Procedure for doing this. The Table Name is TBLEXTRACT_STRING with the same columns and the same values
**ALTER PROCEDURE SP_UPDATELASTCOLUMN
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- VARIABLE DECLARATION SECTION
DECLARE @CNTRECORDS INT
DECLARE @NAMEVALS VARCHAR(50)
DECLARE @I INT
-- SETTING THE INITIAL VALUES
SET @I = 1
SELECT @CNTRECORDS = COUNT(\*) FROM TBLEXTRACT\_STRING
SELECT ROW\_NUMBER() OVER (ORDER BY ID) AS ROWID,\* INTO #TEMP FROM TBLEXTRACT\_STRING
WHILE ( @I <= @CNTRECORDS )
BEGIN
SELECT @NAMEVALS = \[NAME\]
FROM #TEMP
WHERE ROWID = @I
UPDATE TBLEXTRACT\_STRING
SET PART = (SELECT TOP 1 STRINGVAL FROM DBO.FNSPLIT(@NAMEVALS,',')
ORDER BY COUNTER DESC)
WHERE ID = (121 + @I)
SET @I = @I + 1
END
DROP TABLE #TEMP
END
GO**
And the Split function(fnSplit) is as under
**ALTER FUNCTION [dbo].[fnSplit]
(@oldstring as varchar(100),@delimeter as varchar(1))
RETURNS @mytab table(counter int,stringval varchar(100))
AS
Begin
Declare @newstring as varchar(100)
Declare @pos as int
Declare @i as int
Declare @c as int
set @newstring = '';
set @i = 1
set @c = 0
set @pos = CHARINDEX(@delimeter, @oldstring)
WHILE (@i != 0)
Begin
set @c = @c +1
insert into @mytab(counter,stringval) values(@c,@newstring + Substring(@oldstring,0, @pos))
set @oldstring = Substring(@oldstring,@pos+1,len(@oldstring))
set @pos = CHARINDEX(@delimeter, @oldstring)
set @i = @pos;
if (@i = 0)
Begin
set @i = 0;
set @c = @c +1
insert into @mytab(counter,stringval) values(@c,@newstring + @oldstring)
End
End
return
End**
Hope this helps :)
Niladri Biswas