zoukankan      html  css  js  c++  java
  • WHILE (Transact-SQL)

    ---循环
    declare @n int
    declare @rowcount int 
    declare @name varchar(50)
    create table #temp
    (
     id int identity(1,1),
     ColumnNme nvarchar(100)
    )
    insert into #temp select COLUMN_NAME from 数据库名.INFORMATION_SCHEMA.COLUMNS  where TABLE_NAME='表名' --表名
    set @rowcount=@@rowcount
    set @n=1
    while @n<@rowcount
    begin
      select @name=ColumnNme from #temp where id=@n
      print('strSql.Append("'+@name+'=@'+@name+',");')
      set @n=@n+1
    end
    drop table #temp
    --游标
    declare @name nvarchar(max)
    declare geovindu_cursor cursor for select COLUMN_NAME from 数据库名.INFORMATION_SCHEMA.COLUMNS  where TABLE_NAME='表名' --表名
    open geovindu_cursor
    fetch next from geovindu_cursor into @name
    while(@@fetch_status=0)
    begin
      print('strSql.Append("'+@name+'=@'+@name+',");')
      fetch next from geovindu_cursor into @name
    end
    close geovindu_cursor
    deallocate geovindu_cursor
    
    --ms sql里的控制字符列表:
    --Tab   char(9)
    --换行  char(10)
    --回车  char(13)
    --单引号 char(39)
    --双引号 char(34)
    
    WHILE (SELECT AVG(ListPrice) FROM Production.Product) < $300
    BEGIN
       UPDATE Production.Product
          SET ListPrice = ListPrice * 2
       SELECT MAX(ListPrice) FROM Production.Product
       IF (SELECT MAX(ListPrice) FROM Production.Product) > $500
          BREAK
       ELSE
          CONTINUE
    END
    PRINT 'Too much for the market to bear';
    
  • 相关阅读:
    linux系统如何发送邮件
    zabbix监测图形界面显示方框乱码解决方法
    Eclipse C++的配置问题launch failed binary not found
    Cpu表现出正弦曲线
    让cpu跑到100%的bat文件
    进程僵死
    华为一些笔试题~~~~零散总结
    数据库~~~投影与除操作
    C++连接Mysql数据库操作
    微软面试题目及答案
  • 原文地址:https://www.cnblogs.com/geovindu/p/4225885.html
Copyright © 2011-2022 走看看