string-concatenation
Error in ConcatRelated
Here is my table structure: ID1 - autonumber TDate - Date/Time TTime - Date/Time TID - Text TMessage - Text Tcode - text TMessage value can be 100+ characters. There can be more than 1 TMessage for each TID Sample input: TDate TID TTime TMessage 1/9/2014 93378 12:28:28 PM aaaaaaaaaaaa 7/24/2014 02645 12:56:22 PM bbbbbbbbbbbb 7/24/2014 02645 12:56:30 PM cccccccccccc Output should be: TDate, TID, TMessage 1/9/2014 93378 aaaaaaaaaa 7/24/2014 02645 bbbbbbbbbb,cccccccccccc (the output can be more than 255 chars.) This is my query/module (got from Stackoverflow and Allen Brown) Query (SQL View) SELECT sub.TDate, sub.TID, ConcatRelated("[TMessage]","RawData2","[TDate] = '" & sub.TDate & "' AND [TID] = '" & sub.TID & "'","[TDate], [TID]") AS concat_Message FROM (SELECT q.TDate, q.TID FROM RawData2 AS q GROUP BY q.TDate, q.TID) AS sub ORDER BY sub.TDate, sub.TID; Function : Option Compare Database Public Function ConcatRelated(strField As String, _ strTable As String, _ Optional strWhere1 As Date, _ Optional strWhere2 As String, _ Optional strOrderBy1 As Date, _ Optional strOrderBy2 As String, _ Optional strSeparator = ", ") As Variant On Error GoTo Err_Handler 'Purpose: Generate a concatenated string of related records. 'Return: String variant, or Null if no matches. 'Arguments: strField = name of field to get results from and concatenate. ' strTable = name of a table or query. ' strWhere = WHERE clause to choose the right values. ' strOrderBy = ORDER BY clause, for sorting the values. ' strSeparator = characters to use between the concatenated values. 'Notes: 1. Use square brackets around field/table names with spaces or odd characters. ' 2. strField can be a Multi-valued field (A2007 and later), but strOrderBy cannot. ' 3. Nulls are omitted, zero-length strings (ZLSs) are returned as ZLSs. ' 4. Returning more than 255 characters to a recordset triggers this Access bug: ' http://allenbrowne.com/bug-16.html Dim rs As DAO.Recordset 'Related records Dim rsMV As DAO.Recordset 'Multi-valued field recordset Dim strSql As String 'SQL statement Dim strOut As String 'Output string to concatenate to. Dim lngLen As Long 'Length of string. Dim bIsMultiValue As Boolean 'Flag if strField is a multi-valued field. 'Initialize to Null ConcatRelated = Null 'Build SQL string, and get the records. strSql = "SELECT " & strField & " FROM " & strTable If strWhere1 <> vbNullString And strWhere2 <> vbNullString Then strSql = strSql & " WHERE " & strWhere1 And strWhere2 End If If strOrderBy1 <> vbNullString And strOrderBy2 <> vbNullString Then strSql = strSql & " ORDER BY " & strOrderBy1 And strOrderBy2 End If Set rs = DBEngine(0)(0).OpenRecordset(strSql, dbOpenDynaset) 'Determine if the requested field is multi-valued (Type is above 100.) bIsMultiValue = (rs(0).Type > 100) 'Loop through the matching records Do While Not rs.EOF If bIsMultiValue Then 'For multi-valued field, loop through the values Set rsMV = rs(0).Value Do While Not rsMV.EOF If Not IsNull(rsMV(0)) Then strOut = strOut & rsMV(0) & strSeparator End If rsMV.MoveNext Loop Set rsMV = Nothing ElseIf Not IsNull(rs(0)) Then strOut = strOut & rs(0) & strSeparator End If rs.MoveNext Loop rs.Close 'Return the string without the trailing separator. lngLen = Len(strOut) - Len(strSeparator) If lngLen > 0 Then ConcatRelated = Left(strOut, lngLen) End If Exit_Handler: 'Clean up Set rsMV = Nothing Set rs = Nothing Exit Function Err_Handler: MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "ConcatRelated()" Resume Exit_Handler End Function Currently, this is the output: TDate TID Concat_Message 1/9/2014 93378 #Error 7/24/2014 02645 #Error 7/24/2014 04533 #Error Question 1 - What could be the reason for the Error? How to solve it? Question 2 - Can I just create a table manually with Memo field so I can store the result of the Query to this table?
Related Links
ConcatRelated Function Returns All Values
In java properties file itself can we concatenate two or more than two variables together?
“No message” when writing string with console.log()
Moqui:We can use create an view with concatenating two or more columns as single column. simple can we do concatenatio in moqui view creqtion.
Error in ConcatRelated
String Concatenating functions in Progress 4GL?
sybase - simple concatenation
How do you concatenate strings in a Puppet .pp file?