-- 好久不来该论坛啦,据说本论坛高手如云,现将简单问题200分送上 --
http://topic.csdn.net/u/20110401/08/9146992b-03a8-469c-8b53-edf8318cf935.html
-- 现在假设出了个Excel 2010版本,其字段名称能够延伸到8位字母!
-- 要求继续修改上面链接中14楼的函数!(不限思路,只求高效!)
[解决办法]
sfsf
[解决办法]
路过。
[解决办法]
[解决办法]
哈哈,200分不给力,是吧?
[解决办法]
非技术版 ,不给力。
[解决办法]
Excel 2010?不太明白楼主的意思
[解决办法]
create table tb (num int identity(1,1),name varchar(10))declare @a varchar(10)set @a='A'while @a<'Z'begininsert into tb values (@a)set @a=CHAR(ASCII(''+@a+'')+1)end--select * from tb--版本什么的好像不要,无论什么版本只要输入的最大@id不超过该版本支持的最大行数就可以declare @id intset @id=5;with cteas(select ROW_NUMBER() over (order by len(name),name) as id,name from(select name from tbunion allselect a.name+b.name from tb a,tb b) a)select name from cte where id<=@id--其实就是简化为如下;with cteas(select ROW_NUMBER() over (order by len(name),name) as id,name from(select name from tbunion allselect a.name+b.name from tb a,tb b) a)select name from cte where id<=10000--随便自己输入name--------------------ABCDE
[解决办法]
给力。
[解决办法]
学习 ~
[解决办法]
额。。。来啦
[解决办法]
GO
CREATE FUNCTION GetExcelColumnTitle
(@N bigint
)
RETURNS varchar(10)
AS
BEGIN
if @N<=0
return 'Error:01'
declare @Num bigint,@i smallint
declare @C1 char(1),@C2 char(2),@C3 char(1),@C4 char(1),@C5 char(1),@C6 char(1),@C7 char(1),@C8 char(1)
select @Num=@N-1,@i=1
while @Num>25 and @i<8
begin
if @i=1
set @C1= char(65+@Num%26)
else if @i=2
set @C2= char(65+@Num%26)
else if @i=3
set @C3= char(65+@Num%26)
else if @i=4
set @C4= char(65+@Num%26)
else if @i=5
set @C5= char(65+@Num%26)
else if @i=6
set @C6= char(65+@Num%26)
else if @i=7
set @C7= char(65+@Num%26)
set @Num=(@Num/26)-1
set @i = @i+1
end
if @i>8
return 'Error:02'
else if @i=1
set @C1= char(65+@Num%26)
else if @i=2
set @C2= char(65+@Num%26)
else if @i=3
set @C3=char(65+@Num%26)
else if @i=4
set @C4= char(65+@Num%26)
else if @i=5
set @C5= char(65+@Num%26)
else if @i=6
set @C1= char(65+@Num%26)
else if @i=7
set @C7= char(65+@Num%26)
else if @i=8
set @C8= char(65+@Num%26)
return case when @i=1 then @C1
when @i=2 then @C2+@C1
when @i=3 then @C3+@C2+@C1
when @i=4 then @C4+@C3+@C2+@C1
when @i=5 then @C5+@C4+@C3+@C2+@C1
when @i=6 then @C6+@C5+@C4+@C3+@C2+@C1
when @i=7 then @C7+@C6+@C5+@C4+@C3+@C2+@C1
when @i=8 then @C8+@C7+@C6+@C5+@C4+@C3+@C2+@C1
else 'Error:03'
end
END
GO
-- =============================================
-- Example to execute function
-- =============================================
SELECT dbo.GetExcelColumnTitle(703)
--結果:
--AAA
GO
-- 行,谁第一个做出来,我另开一个技术版的给200分!
上述函數可以實現你的要求,3位以下驗算過,但高位數未驗證。兌現承諾,給技術分200分。
[解决办法]
单纯接分
[解决办法]
create table tb_test(id number,chr char(1));
insert into tb_test(id,chr)
select * from (
select 1,'A' from dual union all
select 2,'B' from dual union all
select 3,'C' from dual union all
select 4,'D' from dual union all
select 5,'E' from dual union all
select 6,'F' from dual union all
select 7,'G' from dual union all
select 8,'H' from dual union all
select 9,'I' from dual union all
select 10,'J' from dual union all
select 11,'K' from dual union all
select 12,'L' from dual union all
select 13,'M' from dual union all
select 14,'N' from dual union all
select 15,'O' from dual union all
select 16,'P' from dual union all
select 17,'Q' from dual union all
select 18,'R' from dual union all
select 19,'S' from dual union all
select 20,'T' from dual union all
select 21,'U' from dual union all
select 22,'V' from dual union all
select 23,'W' from dual union all
select 24,'X' from dual union all
select 25,'Y' from dual union all
select 0,'Z' from dual );
[解决办法]
蹭分。。。
[解决办法]
SQL 2008版本的,不复杂,其实就是26进制与10进制的互转问题。
/****** Object: UserDefinedFunction [dbo].[GetRowCharFromNum] Script Date: 04/08/2011 17:09:04 ******/IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetRowCharFromNum]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))DROP FUNCTION [dbo].[GetRowCharFromNum]GOUSE [master]GO/****** Object: UserDefinedFunction [dbo].[GetRowCharFromNum] Script Date: 04/08/2011 17:09:04 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOcreate function [dbo].[GetRowCharFromNum]( @rowNum bigint)returns bigintbegindeclare @FullChar char(26)set @FullChar='ABCDEFGHIJKLMNOPQRSTUVWXYZ'declare @result varchar(30),@lptime int,@tmpNum bigint,@sqr bigintset @sqr=LEN(@FullChar)set @lptime=1set @result=''set @tmpNum=@rowNumwhile (@rowNum>=POWER(@sqr,@lptime-1))begin if(@tmpNum%@sqr=0) begin set @result=substring(@FullChar,@sqr,1)+@result set @tmpNum=@tmpNum/@sqr-1 end else begin set @result=substring(@FullChar,@tmpNum%@sqr,1)+@result set @tmpNum=@tmpNum/@sqr end set @lptime=@lptime+1 endreturn @resultendGO
[解决办法]
能力不够 蹭分
[解决办法]
楼主太奔放,小弟能力不够,只能帮顶
[解决办法]
xue xi
[解决办法]
[解决办法]
学习,帮顶
[解决办法]
不懂我也装懂
[解决办法]
可以接分吗