CONCAT equivalent in MS Access

家住魔仙堡 提交于 2019-11-26 18:26:42

问题


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

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.


回答1:


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

As far as I am aware there is no CONCAT




回答2:


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

"foo" + Null returns Null

"foo" & Null returns "foo"

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

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

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

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

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

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



回答3:


You can use the & operator:

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



回答4:


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

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


来源:https://stackoverflow.com/questions/20403870/concat-equivalent-in-ms-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!