--创建临时表
create table temp
(
id varchar(64),
toneid varchar(256),
songname varchar(256),
author varchar(256),
hotnum varchar(256)
)
--把数据导入临时表中
BULK INSERT temp
FROM 'E:\歌曲数据_201306.txt'
WITH (
FIELDTERMINATOR = '|',
ROWTERMINATOR = '\n'
)
--声明变量
DECLARE @MusicID varchar(256)
DECLARE @HOTID varchar(256)
DECLARE @RESOURCENO varchar(32)
--创建游标
DECLARE contact_cursor CURSOR FOR
SELECT Top(10) [toneid],[hotnum] FROM [MusicSearching40].[dbo].[temp]
--打开游标
OPEN contact_cursor
--抓取数据
FETCH NEXT FROM contact_cursor into @MusicID,@HOTID
WHILE @@FETCH_STATUS = 0
BEGIN
set @MusicID=REPLACE(@MusicID,'^','')
set @HOTID=REPLACE(@HOTID,'^','')
select @RESOURCENO=ToneID from BaseResource.dbo.CrbtInfo where MusicID=@MusicID
print @RESOURCENO
FETCH NEXT FROM contact_cursor
END
--关闭游标
CLOSE contact_cursor
DEALLOCATE contact_cursor
--文本格式如下
1|^63278101499|^一万个舍不得|^庄心妍|^418755
2|^63392000092|^他和她|^郑炳勇|^281675
3|^60054100837|^中华民谣|^冯晓泉|^248190
4|^60054100836|^冰糖葫芦|^冯晓泉|^248175
5|^60051500194|^都是为了爱|^门丽|^236007
6|^60051500300|^玉碎|^冷漠|^230002
7|^60051500301|^小小新娘花|^云菲菲|^223256
8|^63387600020|^我不得不走|^董礼|^221874
9|^63356300083|^要我拿什么来换|^邓金晶|^211301
10|^60058710115|^弦内之音|^弦子|^210927
11|^60058710018|^不在乎他|^张惠妹|^210540
12|^60065200366|^因为爱你|^一赛|^166136