Usage of SQL Server cursors

Source: Internet
Author: User
Tags getdate

Tag:sqlserver    cursor    

declare temp_cursor cursor scroll for    select cityname  from corelinklinshi --  must have an SQL statement here, not empty         open  TEMP_CURSOR    DECLARE  @CityName  varchar ()          FETCH NEXT FROM TEMP_CURSOR INTO  @CityName      while @ @FETCH_STATUS =0    begin         declare  @VALIDTIME  varchar, @ENDTIME  varchar (+)          SET  @VALIDTIME =convert (CHAR), GETDATE (), (+) + '  00:00:00 '          SET  @ENDTIME =convert (CHAR), DATEADD (Day,1,getdate ()), (+) + '  00:00:00 '          while (CONVERT (datetime, @VALIDTIME)  < convert (datetime, @ENDTIME))      &Nbsp;  begin            insert into  dbo. Corelink_temp (cityname,companyno,svrid,neid,nename,slot,boardname,port,validtime)                           values (@CityName, @CompanyNo, @SvrID, @NeID, @NeName, @Slot, @BoardName, @Port, @VALIDTIME)              SET  @VALIDTIME = convert (CHAR), DATEADD (Mi,15,convert (DATETIME, @VALIDTIME)),         END                 FETCH NEXT FROM  temp_cursor into  @CityName     END         close temp_cursor    deallocate temp_cursor


This article is from the "Silent" blog, please be sure to keep this source http://ruiwen.blog.51cto.com/8852761/1564195

Usage of SQL Server cursors

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.