Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在sql中循环表的项列表_Sql_Sql Server_Database_Cursor - Fatal编程技术网

如何在sql中循环表的项列表

如何在sql中循环表的项列表,sql,sql-server,database,cursor,Sql,Sql Server,Database,Cursor,我是sql新手,我希望如此,我有一个表Customer 我在其中添加了一个新字段Region,现在我想做一些 SQL中的更改。我想获取所有记录Customer,并检查每个记录 // This check will perfome for every customer let suppose we have our first customer if currentcustomer.Country = 'US' { UPDATE currentcustomer SET currentcu

我是sql新手,我希望如此,我有一个表
Customer

我在其中添加了一个新字段
Region
,现在我想做一些
SQL中的更改。我想获取所有记录
Customer
,并检查每个记录

 // This check will perfome for every customer let suppose we have our first customer
if currentcustomer.Country = 'US' 
 {
  UPDATE currentcustomer SET currentcustomer.Region=currentcustomer.id
 }
 else
 {
    UPDATE  currentcustomer SET currentcustomer.Region=currentcustomer.ZIP
  }

这就是我想要做的,但我不知道如何在所有客户身上做到这一点,以及如何在sql中做到这一点。请帮帮我,谢谢

@Ahsan-所有记录都有一个国家
美国
或没有
美国
+1,这比我强多了,只是我要用
而不是
=,认为它们是完全相同的吗?@mattytommo-它们在SQL server中,尽管
=
不在ISO标准中。或者单个
更新客户集地区=案例国家,当'us'然后'aa'或者'zz'结束时
@Ahsan-我写的内容将根据
WHERE
标准更新所有
客户
记录。您的编辑没有什么意义-我希望
id
ZIP
是不同的,不兼容的数据类型。你能确切地确认你需要什么吗?假设它的
名称
FName
在发布示例时,请尝试制作它们。好的,示例链接不错。谢谢@Oded
UPDATE Customer SET Region='AA'
WHERE Country = 'US'

UPDATE Customer SET Region='ZZ'
WHERE Country <> 'US'
UPDATE Customer SET Region= id
WHERE Country = 'US'

UPDATE Customer SET Region= Zip
WHERE Country <> 'US'