WHILE (Transact-SQL)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---循环
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';

 

posted @   ®Geovin Du Dream Park™  阅读(321)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2011-01-15 C# 区别浏览器的名称注意的
2011-01-15 C# Exif code,metadata extraction in java读取照片文件的属性
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示