分享

sql循环插入

 秋寒月 2010-11-29
declare @TrackerNumber varchar(15)
declare @Date datetime
declare @Latitude float
declare @Longitude float
declare @Speed float
declare @Direction int
DECLARE temp2 CURSOR FOR 
    SELECT cast(TrackerNumber as varchar(15)),Date,cast(Latitude as float),cast(Longitude as float),cast(Speed as float),Direction FROM imei353327020471926
OPEN temp2; 
--得到一行数据,并将其复制给本地变
FETCH FROM temp2 INTO @TrackerNumber, @Date,@Latitude,@Longitude,@Speed,@Direction;
insert into GpsTrackerData(Gps_Imei,Gps_Datatime,Gps_Latitude,Gps_Longitude,Gps_Speed,Gps_Direction) values(@TrackerNumber, @Date,@Latitude,@Longitude,@Speed,@Direction);
--SQLSTATE 00000: 操作执行成功并且未产生任何类型的警告或异常情况。
--通过这个可以检查是否到达最后一行
while @@FETCH_STATUS=0
begin
FETCH FROM temp2 INTO @TrackerNumber, @Date,@Latitude,@Longitude,@Speed,@Direction;   --在WHILE逻辑中得到更多的行数据
insert into GpsTrackerData(Gps_Imei,Gps_Datatime,Gps_Latitude,Gps_Longitude,Gps_Speed,Gps_Direction) values(@TrackerNumber, @Date,@Latitude,@Longitude,@Speed,@Direction);
end
close temp2

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多