首页 > 开发 > 综合 > 正文

WHILE (Transact-SQL)

2024-07-21 02:47:56
字体:
来源:转载
供稿:网友
WHILE (Transact-SQL)
---循环declare @n intdeclare @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=@@rowcountset @n=1while @n<@rowcountbegin  select @name=ColumnNme from #temp where id=@n  PRint('strSql.Append("'+@name+'=@'+@name+',");')  set @n=@n+1enddrop table #temp--游标declare @name nvarchar(max)declare geovindu_cursor cursor for select COLUMN_NAME from 数据库名.INFORMATION_SCHEMA.COLUMNS  where TABLE_NAME='表名' --表名open geovindu_cursorfetch next from geovindu_cursor into @namewhile(@@fetch_status=0)begin  print('strSql.Append("'+@name+'=@'+@name+',");')  fetch next from geovindu_cursor into @nameendclose geovindu_cursordeallocate geovindu_cursor--ms sql里的控制字符列表:--Tab   char(9)--换行  char(10)--回车  char(13)--单引号 char(39)--双引号 char(34)WHILE (SELECT AVG(ListPrice) FROM Production.Product) < $300BEGIN   UPDATE Production.Product      SET ListPrice = ListPrice * 2   SELECT MAX(ListPrice) FROM Production.Product   IF (SELECT MAX(ListPrice) FROM Production.Product) > $500      BREAK   ELSE      CONTINUEENDPRINT 'Too much for the market to bear';


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表