技術(shù) 點(diǎn)
- 技術(shù)
- 點(diǎn)
- V幣
- 點(diǎn)
- 積分
- 8225
|
DCONCAT 函數(shù)
可以使用 DCONCAT 函數(shù)連接指定的一組記錄(域)中的一組值的字符串。
可以在 Visual Basic、宏、查詢(xún)表達(dá)式或者計(jì)算控件中使用 DCONCAT 函數(shù)。
(ADO/DAO不支持)。
例如,可以在查詢(xún)中使用 DCONCAT 函數(shù)。
select customerID, DCONCAT('orderID','orders','customerID=' & customerID
from customers
DCONCAT(expr, domain, [criteria],[delimiter])
DCONCAT 函數(shù)具有下列參數(shù)。
參數(shù) 說(shuō)明
expr 表達(dá)式,用于標(biāo)識(shí)要計(jì)算其記錄數(shù)的字段。它可以是標(biāo)識(shí)表或查詢(xún)中
字段的字符串表達(dá)式,也可以是對(duì)該字段中的數(shù)據(jù)執(zhí)行計(jì)算的表達(dá)式。
在 expr 中,可以包含表中字段的名稱(chēng)、窗體上的控件、常量或函數(shù)。
如果 expr 包含一個(gè)函數(shù),那么它可能是內(nèi)置或用戶(hù)定義的函數(shù),但
不是另一個(gè)域聚合函數(shù)或 SQL 聚合函數(shù)。
domain 字符串表達(dá)式,用于標(biāo)識(shí)組成域的一組記錄。它可以是表名稱(chēng)或不需
要參數(shù)的查詢(xún)的查詢(xún)名稱(chēng)。
criteria 可選字符串表達(dá)式,用于限制對(duì)其執(zhí)行 DCONCAT 函數(shù)的目標(biāo)數(shù)據(jù)的范
圍。例如,criteria 通常等價(jià)于 SQL 表達(dá)式中的 WHERE 子句,但它
沒(méi)有單詞 WHERE。如果 criteria 被省略,那么 DCONCAT 函數(shù)將針對(duì)
整個(gè)域計(jì)算 expr。任何包含在 criteria 中的字段必須也是 domain
中的字段;否則 DCONCAT 函數(shù)將返回 錯(cuò)誤信息。
delimiter 可選字符串表達(dá)式,用于分隔各記錄的字符串值。默認(rèn)值為逗號(hào)"," 。
函數(shù)實(shí)現(xiàn)
'*******************************************************************************
' DCONCAT(expr, domain, [criteria],[delimiter])
'
' Function: to concate the columns string like group_concat() in Access.
' Parameter:
' expr : string, expression which can recognized by SQL.
' domain : string, the row source, can be another query.
' criteria : the ceritera which will be treated as the where clause.
' delimiter : delimiter between the column value, default is ",".
'
' Return: string, a String of concated columns,
' if err, return the err code + desc.
'
' history:
' 2009-Feb-28 ACMAIN New Creation
'
'*********************************************************************************
Public Function DCONCAT(sExpr As String, sDomain As String, Optional sCriteria As String, Optional sDelimiter As String = ",")
On Error GoTo ErrHandler
Dim rs As New ADODB.Recordset
Dim sSQL As String
Dim sResult As String
sResult = ""
sSQL = "select " & sExpr & " from (" & sDomain & ")"
If sCriteria <> "" Then
sSQL = sSQL & " where " & sCriteria
End If
rs.Open sSQL, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
Do While Not rs.EOF
If sResult <> "" Then
sResult = sResult & sDelimiter
End If
sResult = sResult & rs.Fields(0).Value
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
DCONCAT = sResult
Exit Function
ErrHandler:
If rs.State <> adStateClosed Then
rs.Close
End If
Set rs = Nothing
DCONCAT = Err.Number & " : " & Err.Description
End Function
VBA 中類(lèi)似EXCEL 中的MAX() 函數(shù)實(shí)現(xiàn)
******************
* 一切皆有可能 *
******************
.
ACMAIN - Access論壇回貼準(zhǔn)則(個(gè)人).
.
同一貼子不回復(fù)第二次
.
QQ群 48866293 / 12035577 / 7440532 / 13666209
http://forum.csdn.net/BList/OtherDatabase .
http://www.accessbbs.cn/bbs/index.php .
http://www.accessoft.com/bbs/index.asp .
http://www.access-programmers.co.uk/forums .
http://ctxi.cn .
.
http://ctxi.cn/home/space.php?uid=141646 . |
|