日期:2014-05-17 浏览次数:20541 次
--===============================================================
-- 文件头16个字节剖析(日线)
-- 0x6864312E3000 6 固定
-- 0x???????? 4 记录数
-- 0x4800 2 记录开始位置: 64是错的, 文件头 + 列定义 = 72
-- 0x3800 2 每记录的长度: 56
-- 0x0E00 2 每记录的列数: 14
-----------------------------
-- 列定义: 04表示列长度
-- 0x01300004 4 日期
-- 0x07700004 4 开盘价
-- 0x08700004 4 最高价
-- 0x09700004 4 最低价
-- 0x0B700004 4 收盘价
-- 0x13700004 4 成交金额(元)
-- 0x0D700004 4 成交量(股)
-- 0x0E700004 4 FFFFFFFF
-- 0x0F700004 4 FFFFFFFF
-- 0x11700004 4 FFFFFFFF
-- 0x12700004 4 FFFFFFFF
-- 0x50700004 4 FFFFFFFF
-- 0xE7700004 4 FFFFFFFF
-- 0xE8700004 4 FFFFFFFF
--===============================================================
if object_id('tempdb.dbo.#') is not null drop table #
go
declare @ varbinary(max), @max int, @e float
select @ = BulkColumn, @e = 10 from OPENROWSET(BULK N'X:\...\history\shase\day\600787.day', SINGLE_BLOB) as bin
select @max = substring(@,10,1)+substring(@,9,1)+substring(@,8,1)+substring(@,7,1)
select top (@max) n = identity(int,72,56) into # from syscolumns a, syscolumns b
;with cte as
(
select
-- SQL没有提供按字节reverse(binary)的函数或方法,只能substring每个字节倒过来合成:
d = convert(int,substring(@, 4+n,1)+substring(@, 3+n,1)+substring(@, 2+n,1)+substring(@, 1+n,1)),
o = convert(int,substring(@, 8+n,1)+substring(@, 7+n,1)+substring(@, 6+n,1)+substring(@, 5+n,1))&0x0FFFFFFF,
p = convert(int,substring(@,12+n,1)+substring(@,11+n,1)+substring(@,10+n,1)+substring(@, 9+n,1))&0x0FFFFFFF,
q = convert(int,substring(@,16+n,1)+substring(@,15+n,1)+substring(@,14+n,1)+substring(@,13+n,1))&0x0FFFFFFF,
r = convert(int,substring(@,20+n,1)+substring(@,19+n,1)+substring(@,18+n,1)+substring(@,17+n,1))&0x0FFFFFFF,
s = convert(int,substring(@,24+n,1)+substring(@,23+n,1)+substring(@,22+n,1)+substring(@,21+n,1))&0x0FFFFFFF,
t = convert(int,substring(@,28+n,1)+substring(@,27+n,1)+substring(@,26+n,1)+substring(@,25+n,1))&0x0FFFFFFF,
u = convert(int,substring(@, 8+n,1))/16,
v = convert(int,substring(@,12+n,1))/16,
w = convert(int,substring(@,16+n,1))/16,
x = convert(int,substring(@,20+n,1))/16,
y = convert(int,substring(@,24+n,1))