简体   繁体   English

在MS Access中使用SQL在VBA中进行类型转换?

[英]Type casting in VBA using SQL in MS Access?

I need to convert all the records of a NON-Unicode table into a Unicode table by using something like the CAST function in SQL Server which looks like this: 我需要使用类似SQL Server中的CAST函数,将NON-Unicode表的所有记录转换为Unicode表,如下所示:

Cast ([Transaction_No] as [nvarchar](14))


But now I'm using MS Access so can I do a type casting in the VBA code? 但是现在我正在使用MS Access,所以可以在VBA代码中进行类型转换吗?
Or is there another work around that could solve this problem for me? 还是有其他解决方法可以为我解决这个问题?

In my table t_Transaction I have this field: TRANSACTION_NO, defined as 在我的表t_Transaction中,我具有以下字段:TRANSACTION_NO,定义为

DateType=Text, FieldSize=50    

And what I want it to be: 我想要的是:

DateType=Number, FieldSize=Integer

Assuming that the string values are all valid integers you can use: 假设字符串值都是有效的整数,则可以使用:

CInt(YourStringValue)

There are various other converstion functions along these lines (CBool(), CStr() etc). 这些方面还有其他各种对话函数(CBool​​(),CStr()等)。

You can even avoid this entirely as you should be able to implicitly convert them in VBA: 您甚至可以完全避免这种情况,因为您应该能够在VBA中隐式转换它们:

YourIntegerVariable = YourStringValue

In Access everything is treated as Unicode. 在Access中,所有内容均视为Unicode。 You will not have to make any casts from non-Unicode to Unicode. 您无需从非Unicode到Unicode进行任何转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM