sql server里将十六进制转换成十进制
在网上找了很多,总是不知道怎么用,于是自己写了一个:
declare @strHex char(5),
@len int,
@intOut int,
@i int,
@charint int
set @strHex = '20'
set @len = len(rtrim(@strHex))
set @i = 1
set @intOut = 0
while @i <= @len
begin
set @charint = case substring(upper(rtrim(ltrim(@strHex))),@i,1)
when 'A' then 10
when 'B' then 11
when 'C' then 12
when 'D' then 13
when 'E' then 14
when 'F' then 15
else substring(@strHex,@i,1)
end
set @intOut = @intOut +@charint * power(16, @len-@i)
set @i = @i + 1
end
print @intOut
由于要批量修改,帮写成了游标的形式:
use pubs
declare @strHex char(5),
@len int,
@intOut int,
@i int,
@charint int,
@keyname char(50)
declare hextoint cursor for
select rtrim(col001),rtrim(col002) from vv
open hextoint
fetch next from hextoint into @keyname,@strHex
while @@fetch_status =0
begin
set @len = len(rtrim(@strHex))
set @i = 1
set @intOut = 0
while @i <= @len
begin
set @charint = case substring(upper(rtrim(ltrim(@strHex))),@i,1)
when 'A' then 10
when 'B' then 11
when 'C' then 12
when 'D' then 13
when 'E' then 14
when 'F' then 15
else substring(@strHex,@i,1)
end
set @intOut = @intOut +@charint * power(16, @len-@i)
set @i = @i + 1
end
update vv set col002 = @intout where col001 = rtrim(@keyname)
--print @intOut
fetch next from hextoint into @keyname,@strHex
end
close hextoint
deallocate hextoint
记以下留作以后参考吧。
相关文档:
今天抽出一点时间解释几个关于SQL日志的概念,他们也经常使初学者望而止步,反正计算机的术语都是很抽象的,所以第一感觉就是头疼,然后然后几次后就没感觉了.以下有些是从书上摘抄的,有的是从网上找的算是借花献佛吧!!
物理日志文件:
这个比较好理解,实实在在的东西,数据库目录下面的.ldf文件 ......
Truncate Logs for SQL Server 2008
I had previously posted how to Truncate Logs for SQL Server 2005. Unfortunately, this method does not work in SQL Server 2008. The reason is because the “WITH TRUNCATE_ONLY” command is no longer in SQL 2008. Assuming you run in full recovery mode, the n ......
begin
for item in (select * from user_constraints a where a.constraint_type = 'R') loop
execute immediate 'alter table ' || item.table_name || ' disable constraint ' || item.constraint_name;
end loop;
end;
/ ......
我们知道用powerdesigner导出的sql文件后缀为'.sql';用phpmyadmin很容易导入MysQL数据库,但是用PHP怎么导入数据库呢?
我用powerdesigner设计一个数据库后导出sql文件(一个投票系统)为'vote.sql';
文件内容为(一些sql语句和注释):
/*======================= ......
事务就是负责把一系列操作看做一个独立的逻辑单元,这些操作要么同时成功,要么同时失败。下面是一个经典的例子:
create procedure TransferMoeny
(
@fromAccountNo varchar(50),-- 转出账号
@ToAccountNo varchar(50),--转入账号
& ......