zoukankan      html  css  js  c++  java
  • SQL2005 遍历表插入

    /* sql2005遍历表(方法1)
    insert into 数据表(userid,adddate) values((select userid from 用户表),date);
    */
    
    
    /*sql2005 表变量遍历表(方法2)*/
    --表变量
    declare
    @i int declare @ChannelID int declare @ChannelUpdateRoomCount int --nvarchar(50) --遍历 set @i=(select min(XH_ChannelID) from XH_Channel where XH_ChannelState=0) --遍历表中的每一行 while (@i<=(select max(XH_ChannelID) from XH_Channel where XH_ChannelState=0)) begin select @ChannelID=XH_ChannelID,@ChannelUpdateRoomCount=XHService_UpdateRoomCount from XH_Channel where XH_ChannelState=0 and XH_ChannelID=@i select @i=min(XH_ChannelID) from XH_Channel where XH_ChannelState=0 and XH_ChannelID>@i --遍历ID,查找价格表不存在的数量批量插入 insert Tts_Hotel_PriceRoomState (Hrs_Date,Hrs_roomID,Hrs_HID, Hrs_ChannelID,Hrs_RoomCount,Hrs_optUser) select Hp_Date,Hp_roomID,Hp_HID, @ChannelID,@ChannelUpdateRoomCount,'系统批量' from Tts_Hotel_Price left join Tts_Hotel_PriceRoomState on Hp_Date=Hrs_Date and Hp_roomID=Hrs_roomID and Hrs_ChannelID=@ChannelID where Hrs_Id is null end
  • 相关阅读:
    网络基础复习02
    网络基础复习01
    python 基础复习之数据库02
    python 基础复习之数据库01
    python 基础复习 13
    python基础复习 12
    python基础复习 11
    python基础复习10
    列表切片,内置方法
    文件操作基础流程
  • 原文地址:https://www.cnblogs.com/Fooo/p/3485813.html
Copyright © 2011-2022 走看看