在SQL(Microsoft access)中合并表和修改字符串记录
初学者SQL问题。假设我有两张桌子 表1在SQL(Microsoft access)中合并表和修改字符串记录,sql,string,ms-access-2007,Sql,String,Ms Access 2007,初学者SQL问题。假设我有两张桌子 表1 ID name1 name2 name3 -- ----- ----- ----- 1 blah1 high south 2 blah2 low north 3 blah3 high north 4 blah4 low south ID name1 name2 name3 -- ----- ----- ----- 1 blah1 high south 2 blah2 low north 3 blah3 hig
ID name1 name2 name3
-- ----- ----- -----
1 blah1 high south
2 blah2 low north
3 blah3 high north
4 blah4 low south
ID name1 name2 name3
-- ----- ----- -----
1 blah1 high south
2 blah2 low north
3 blah3 high north
4 blah4 low south
5 blah5 high south
6 blah6 high north
7 blah7 low north
8 blah8 low south
表2
ID head1 head2
-- ----- ----------
1 blah5 super high south
2 blah6 medium high northern
3 blah7 kind of low north
4 blah8 kind of low south
现在我想把表2的记录添加到表1中。但在表1的标题2中,列name2和name3的数据以字符串形式组合在一起。所以我想从head2'中提取这些字段,并将它们放入Table1'中,使其看起来像这样
表1
ID name1 name2 name3
-- ----- ----- -----
1 blah1 high south
2 blah2 low north
3 blah3 high north
4 blah4 low south
ID name1 name2 name3
-- ----- ----- -----
1 blah1 high south
2 blah2 low north
3 blah3 high north
4 blah4 low south
5 blah5 high south
6 blah6 high north
7 blah7 low north
8 blah8 low south
现在我想到了某种IF语句,但不知道如何在SQL中实现它
for each record in table2 do
table1.name1.insert(head1)
if table2.head2 == "super high south" then
table1.name2.insert(high)
table1.name3.insert(south)
if table2.head2 == "medium high northern" then
table1.name2.insert(high)
table1.name3.insert(north)
etc....
在我的实际应用程序中,head2中的唯一字符串类型数量有限,因此每个类型的if语句都是可行的
如何为Microsoft Access编写SQL查询来完成此操作?使用数量有限的[head2]值,您可以使用如下切换函数对if语句逻辑进行编码: 在表1中插入名称1、名称2、名称3 选择 标题1作为名称1, 转换 水头2=超高南部,高, 水头2=中高北高, 人头2=有点北低,低, 人头2=有点南低,低 作为名字2, 转换 头2=超高南部,南部, head2=中高北部、北部、, 人头2=有点低,北,北, 人头2=有点低,南,南 名称3 来自表2
不清楚你想做什么。blah5、blah6等的name2和name3值来自哪里?最简单的方法可能是为high、low等创建一个关键字表,并创建一个查询来评估表2中head2 like关键字的数据。这将变得复杂,如果你有两个关键字,如超高。