【问题标题】:Microsoft Access Data Base .. Select QueryMicrosoft Access 数据库 .. 选择查询
【发布时间】:2010-02-12 00:40:40
【问题描述】:

我正在 Microsoft Access 中进行查询练习。我想将名字与传真号码连接起来.. 传真号码就像 (123)555-0103 .. 我正在这样做

select [first name] +' ''s Fax Number is' +str(fax number) as [Mariya`s Fax Number] 
from employees where id =4;

但它给出了错误..

【问题讨论】:

  • 请告诉我们它给出的错误
  • 查询表达式'[first name] +' ''s Fax number is '+str(fax number)'中的语法错误(缺少运算符)。
  • Google for "access combine strings": techonthenet.com/access/functions/string/concat.php 它说:"string" & "another" 输出 "stringanother"
  • 使用 & 连接运算符,您无需将传真号码强制转换为字符串数据类型。在 Jet/ACE SQL 和 VBA 中,+ 运算符为非数字数据传播 Null,但对数字执行加法。在 Access 中,默认情况下使用 & 进行连接,仅当您想要传播 Null 时才使用 + 进行连接(例如,Mid(("12"+LastName) & (", "+FirstName), 3) 以获得“Fenton ,大卫”的名字)。

标签: ms-access


【解决方案1】:

那就是:

select [first name] & " ''s Fax Number is " & [fax number] as [Mariya`s Fax Number] 
from employees where id =4

你应该使用 & 来连接
您应该为每个单引号使用 ''
您应该对字符串使用双引号 (")。

【讨论】:

  • 当您不想传播 Null 时,应该使用 & 进行连接。如果 [fax number] 不是数字,当传真号码为 Null 时,+ 连接运算符将只给您名字,而使用 & 您将得到“FirstName's Fax Number is”,这可能是不可接受的。电话号码真的不应该被存储为数字,所以它很可能与 [FirstName] & ("'s Fax Number is"+[FaxNumber]) 一起工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-23
  • 2010-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多