SQL MS Access 中的 CONCAT 等效项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20403870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 23:20:39  来源:igfitidea点击:

CONCAT equivalent in MS Access

sqlms-accessms-access-2010

提问by salty

I'm doing some work in MS Access and I need to append a prefix to a bunch of fields, I know SQL but it doesn't quite seem to work the same in Access

我正在 MS Access 中做一些工作,我需要在一堆字段中附加一个前缀,我知道 SQL,但它在 Access 中似乎不太一样

Basically I need this translated to a command that will work in access:

基本上,我需要将其转换为可用于访问的命令:

UPDATE myTable
SET [My Column] = CONCAT ("Prefix ", [My Column]) 
WHERE [Different Column]='someValue';

I've searched up and down and can't seem to find a simple translation.

我上下搜索,似乎找不到简单的翻译。

回答by HansUp

There are two concatenation operators available in Access: +; and &. They differ in how they deal with Null.

Access 中有两个连接运算符:+; 和&。它们在处理 Null 的方式上有所不同。

"foo" + Nullreturns Null

"foo" + Null返回空

"foo" & Nullreturns "foo"

"foo" & Null返回 "foo"

So if you want to update Null [My Column]fields to contain "Prefix "afterwards, use ...

因此,如果您想更新 Null[My Column]字段以在"Prefix "之后包含,请使用 ...

SET [My Column] = "Prefix " & [My Column]

But if you prefer to leave it as Null, you could use the +operator instead ...

但是,如果您希望将其保留为 Null,则可以改用+运算符...

SET [My Column] = "Prefix " + [My Column]

However, in the second case, you could revise the WHEREclause to ignore rows where [My Column]contains Null.

但是,在第二种情况下,您可以修改WHERE子句以忽略[My Column]包含 Null 的行。

WHERE [Different Column]='someValue' AND [My Column] Is Not Null

回答by Fred

UPDATE myTable
SET [My Column] = "Prefix " & [My Column] 
WHERE [Different Column]='someValue';

As far as I am aware there is no CONCAT

据我所知,没有 CONCAT

回答by Gordon Linoff

You can use the &operator:

您可以使用&运算符:

UPDATE myTable
    SET [My Column] = "Prefix " & [My Column]
    WHERE [Different Column]='someValue';

回答by Kiril Rusev

Since there is no Concat function in MS-ACCESS, you can simply combine both strings with +operator:

由于 MS-ACCESS 中没有 Concat 函数,您可以简单地将两个字符串与+运算符组合起来:

  UPDATE myTable
 SET [My Column] = "Prefix " + [My Column]
 WHERE [Different Column]='someValue';