I need to know column name of a spread sheet with a given starting colum upto n number of columns let say starting column is "AB", I want to know the column (label) after 99 columns.
For those who need Ralph answer in T-SQL flavor
Create FUNCTION fsExcelValueToColum(@value int) returns varchar(3) as
begin
DECLARE @DIGIT INT,@RV VARCHAR(3);set @rv=''
IF @VALUE=0 RETURN @rv
WHILE @VALUE > 0
BEGIN
SET @DIGIT = @VALUE % 26
IF @DIGIT = 0
BEGIN
set @RV=@RV+'Z'
set @RV=@RV+dbo.fsExcelValueToColum(@value /26 -1)
return @rv
END
set @rv=@rv+char(@digit+64)
set @value=(@value-@digit) /26
END
return @rv
end
USE [ecs]
GO
/****** Object: UserDefinedFunction [dbo].[fnExcelColumnToValue] Script Date: 12/06/2009 10:33:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[fnExcelColumnToValue](@Column varchar(3)) returns int as
Begin
--declare @column varchar(10); select @column = 'AC'
declare @value int, @pow int,@i int,@n int
select @pow=1,@VALUE=0,@I=LEN(@COLUMN)
SET @I=LEN(@COLUMN)
WHILE @I >= 1
BEGIN
SET @VALUE=@VALUE+@POW*((ASCII(SUBSTRING(UPPER(@COLUMN),@I,1)) - 65) +1)
SET @POW=@POW *26
SET @I=@I-1
END
return @value
end