将NVARCHAR数据类型转换为MS Access PassThrough查询中的数字以进行后续计算
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于这是PT查询,因此您可以这样铸造:
因此,用于铸造:
Since this is a pt query, then you can cast it like this:
So, for cast: