啊,你要到Z呀,那ZZ是不是就是2626?
解决方案 »
- 这是2004年上半年的一道高程考试题,看了好长时间没看出什么意思,谁帮解释解释!!!
- 各位大哥,安装SQL server失败,帮我看看啊!
- 有关sp_addlinkedserver的问题,急!!
- 用存储过程将数字型ip地址转换四段式??
- sqlserver插入数据中文显示为???, 为什么?
- 求教:如何按精确的日期查询
- 我在计算时,如果分母为0就出错了怎么解决?Divide by zero error encountered.
- SQL Server安装时提示文件挂起
- 能在存储过程内建立视图吗?
- SQL SERVER TRIGGER
- DTS的JScript脚本如何调用SQL自定义函数?
- 插入数据时的排序问题?
returns bigint
as
begin
declare @i bigint
declare @c varchar(2)
set @i = 0
while(len(@str)>0)
begin
set @c=UPPER(LEFT(@str,1))
if(@c between 'A' and 'Z')
set @i=@i*26+ASCII(@c)-64
else
return null
set @str=stuff(@str,1,1,'')
end
return @i
end
goselect dbo.f_convert('')
/*
----
0
*/
select dbo.f_convert('AC')
/*
----
29
*/
select dbo.f_convert('12')
/*
----
NULL
*/drop function f_convert
go
(
@inChar nvarchar(30)
)
RETURNS int
AS
BEGIN
declare @m int,@len int,@tmpAscii int
set @len = len(@inChar)
set @m = 1
set @tmpAscii=0
while @m < = @Len
begin
set @tmpAscii=@tmpAscii*26 + (ascii(SUBSTRING(@inChar,@m,1))-64)
set @m = @m + 1
end
return @tmpAsciiEND
以上是转换成数字的。
下面是从数字转换成字符的:
ALTER FUNCTION dbo.MyVarchar
(
@InNumber int
)
RETURNS nvarchar(30)
AS
begin
declare @mod int,@s nvarchar(30),@quotient int
set @s=''
set @quotient = @InNumber
while @quotient>0
begin
set @mod=@quotient%26
set @quotient=@quotient/26
if @mod=0
begin
set @mod=26
set @quotient=@quotient-1
end
set @s =CHAR(@mod+64)+@s
end
return @s
end