这是我的第一个问题,很抱歉,如果它是重复的,我似乎无法以引起相关结果的方式来表达它。
本质上,我试图从SQL中提取一个仅显示“收件箱”的值
我有一个功能可以做到这一点:
Function MailboxInbox(activeEmail As String,activeEmailInbox As String,ValidMailbox,conn As ADODB.Connection,rs As ADODB.Recordset,sConnString As String)
Call OpenSQLCon.ConnectSqlServer(conn,rs,sConnString)
Dim SQL As String
SQL = "Select distinct coalesce(Mailbox_1,Mailbox_2,Mailbox_3) from [MAP].[Config].[TB_SU_MAP_Mailbox_Configuration] where Mailbox_Name ='" & activeEmail & "'"
Debug.Print SQL
' Open the connection and execute.
conn.Open sConnString
Set rs = conn.Execute(SQL)
If rs.EOF = True Or rs.BOF = True Then
ValidMailbox = 1
Exit Function
Else
activeEmailInbox = rs(0)
Debug.Print activeEmailInbox
End If
'Close SQL
Call CloseSQLCon.CSC(conn,sConnString)
End Function
在这种情况下,我要连接到SQL Server,通过查询发送要执行的内容,并取回我放入记录集中的单个值。这部分工作正常。在SQL表中,值为“收件箱”,五个字符,不包含“。
但是,当我使用记录集中的值填充变量'activeEmailInbox'时,会将其设置为“收件箱
稍后在代码中使用此值时,由于将其设置为“收件箱,因此无法将要查看的邮箱设置为”收件箱“。我是在将值activeEmailInbox打印到显示Inbox的调试窗口时显示的。
任何帮助将不胜感激。谢谢。