将NVARCHAR数据类型转换为MS Access PassThrough查询中的数字以进行后续计算

发布于 2025-01-20 19:03:41 字数 740 浏览 0 评论 0原文

我正在 MS Access 环境中使用 SQL 直通到 SQL Server 查询。我在 Access 表单中显示查询结果,并在文本框中对其执行显示计算。

SQL Server 中的数据类型为 nvarchar。在直通查询中,我修剪了 select 语句中的空格。数据的所有其他用途都支持这种剩余的文本类型。但我想在某个特定位置显示时减去一个值。

直通看起来像这样:

Select
  ,Trim([NumberStoreAsTextWithSpaces]) as NumberStoredAsTextNoSpaces
  ,[Other stuff]
  ,[Other stuff1]
  ,[Other stuff2]
  ,[Other stuff...]
From [dbo].[Table of Numbers of Stuff]

当我访问表单的控件数据源是直通查询,并且在文本框控件中,控件数据源是:

=[NumberStoredAsTextNoSpaces]-42.0

这导致 #Type! 作为结果出现在文本框中。

在减法运算之前尝试使用 CDbl() 会导致零值或空值减去 42.0,并在文本框中简单地显示为 -42.0。

我不一定关心查询中是否有错误的数据项,Select ... Trim 会直接跳过该数据项。 Access 表单应该只在光标处出错。

我缺少什么?

I'm working with a SQL passthrough to SQL Server query in a MS Access environment. I'm displaying the query results in an Access form and performing a display calculation to it in a text box.

The data type is nvarchar in SQL Server. In the passthrough query I trim spaces in the select statement. All other uses of the data support this remaining a text type. But I would like to subtract a value when displayed in one particular place.

The passthrough looks like this:

Select
  ,Trim([NumberStoreAsTextWithSpaces]) as NumberStoredAsTextNoSpaces
  ,[Other stuff]
  ,[Other stuff1]
  ,[Other stuff2]
  ,[Other stuff...]
From [dbo].[Table of Numbers of Stuff]

When I get to Access the control data source of the form is the passthrough query, and in the text box control the control data source is:

=[NumberStoredAsTextNoSpaces]-42.0

This results in #Type! as a result in the text box.

Attempting to CDbl() prior to the subtraction operation results in a zero or null value minus the 42.0 and simply shows as -42.0 in the text box.

I don't necessarily care if there is a bad data item somewhere in the query, the Select ... Trim jumps right over that. And the Access form should only error at the cursor.

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过潦 2025-01-27 19:03:41

由于这是PT查询,因此您可以这样铸造:

Select
,CAST(Trim([NumberStoreAsTextWithSpaces]) AS real) as NumberStoredAsTextNoSpaces
,[Other stuff]
,[Other stuff1]
,[Other stuff2]
,[Other stuff...]
From [dbo].[Table of Numbers of Stuff]

因此,用于铸造:

 int (Access long)
 float (Access double)
 real  (Access single)
 money (Access currency)
 

Since this is a pt query, then you can cast it like this:

Select
,CAST(Trim([NumberStoreAsTextWithSpaces]) AS real) as NumberStoredAsTextNoSpaces
,[Other stuff]
,[Other stuff1]
,[Other stuff2]
,[Other stuff...]
From [dbo].[Table of Numbers of Stuff]

So, for cast:

 int (Access long)
 float (Access double)
 real  (Access single)
 money (Access currency)
 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文