如何在 Select * 中引用自定义函数?
比如表 P_History数据库(Access)的数据如下:程序代码:
C_ID M_ID P_ID 20120102 01001 0 20120103 01001 0 20120104 01001 1 20120105 01003 1 20120106 02001 0 20120107 02001 2 20120108 02001 0 20120109 02001 1 20120110 01003 2
P_ID中:0表示Ok,1表示Fail,2表示,UnKnow,如何显示出这样的结果呢:
程序代码:
C_ID M_ID P_ID 20120102 01001 ok 20120103 01001 ok 20120104 01001 Fail 20120105 01003 Fail 20120106 02001 ok 20120107 02001 Unknow 20120108 02001 ok 20120109 02001 Fail 20120110 01003 Unknow
自定义函数:
程序代码:
Function Str_PM_Result(ByVal str_P As String) As String If str_P = "0" Then Str_PM_Result = "For Schedule PM" ElseIf str_P = "1" Then Str_PM_Result = "For Down PM" Else Str_PM_Result = "For Schedule PM" End If End Function
sql = "select C_ID,M_ID," & Str_PM_Result(P_ID) & " from P_History"
如上语句,但是P_ID栏目为空,并不是 Ok/Fail/Unknow"?
或者有时会出现错误:
出现错误: -2147217900 语法错误(操作符丢失)正查询表达式 'For Schedule PM' 中
或者:
SELECT IIF(P_Id=0,'OK',IIF(P_ID=1,'fail','unknow')) AS P_Id FROM
但是 P_ID栏目还是为空,不知道哪里出错了...