Click here to Skip to main content
15,919,613 members
Home / Discussions / Database
   

Database

 
AnswerRe: How to build a DataBase of data types (int, char, struct, …)? Pin
ekolis25-May-04 9:10
ekolis25-May-04 9:10 
GeneralRe: How to build a DataBase of data types (int, char, struct, …)? Pin
Michigan185426-May-04 20:14
Michigan185426-May-04 20:14 
GeneralShrink Database Pin
mhmoud rawas16-May-04 22:52
mhmoud rawas16-May-04 22:52 
GeneralRe: Shrink Database Pin
mtone18-May-04 7:25
mtone18-May-04 7:25 
Generalhelp Pin
romadoma14-May-04 12:04
romadoma14-May-04 12:04 
GeneralRe: help Pin
Mazdak14-May-04 21:07
Mazdak14-May-04 21:07 
GeneralHelp with SQL statement Pin
xfitr214-May-04 7:04
xfitr214-May-04 7:04 
GeneralRe: Help with SQL statement Pin
Mike Ellison18-May-04 6:28
Mike Ellison18-May-04 6:28 
Hi Garrett. You may want to have a subquery take care of the [Count] and [Ages] fields, with a custom function to derive [Ages]. Start with a custom function to return an age given a birthdate. Here is a good function that comes from a Microsoft KB article:
Function Age(varBirthDate As Variant) As Integer
    Dim varAge As Variant

    If IsNull(varBirthDate) Then Age = 0: Exit Function

    varAge = DateDiff("yyyy", varBirthDate, Now)
    If Date < DateSerial(Year(Now), Month(varBirthDate), _
                         Day(varBirthDate)) Then
       varAge = varAge - 1
    End If
    Age = CInt(varAge)
End Function
Then create a function that takes a parent id (l_Mem_ID in your case) and returns a string of ages for each child. This can be done by executing a query on the fly and looping through the resulting recordset:
Function GetAgesOfChildren(parentID As Integer) As String
 
    Dim sResult As String
    Dim sSql As String
    Dim conn As ADODB.Connection
    Dim rst As ADODB.Recordset
     
    Set conn = Application.CurrentProject.Connection
    Set rst = New ADODB.Recordset
     
    '--select statement uses the Age() function
    sSql = "Select Age(DOB) From tbl_Children Where l_Mem_ID = " _
               & parentID & " Order By Age(DOB)"
     
    '--open the recordset
    rst.Open sSql, conn
     
    sResult = ""
    '--loop through the recordset to create a concatentated string
    While Not (rst.EOF)
        If sResult <> "" Then sResult = sResult & ", "
        sResult = sResult & CStr(rst(0))
        rst.MoveNext
    Wend
     
    GetAgesOfChildren = sResult
     
    Set rst = Nothing
    Set conn = Nothing
 
End Function
It won't be particularly effecient, but it will get the job done. Your subquery could then just link tbl_Customers to tbl_Children, use the Group By option with the Count() function for your [Count] field, then use the following as an expression for the third [Ages] field in the query grid:
Field--  Ages: GetAgesOfChildren([tbl_Customers].[l_Mem_id])
Table--
Total--  Expression
Make the join between tbl_Customers and tbl_Children a left outer join and you'll get zero values for those customers without children records, rather than having those records drop off. Finally then, you can use this subquery in your main query with the tbl_LATCH table to get your final result set.

I hope this helps.
GeneralHelp...Datagrid and Ado question Pin
gen2314-May-04 0:17
gen2314-May-04 0:17 
QuestionHow to run a CS program at client without SQL Server! Pin
tuliplanetrain13-May-04 22:50
tuliplanetrain13-May-04 22:50 
AnswerRe: How to run a CS program at client without SQL Server! Pin
Aryadip14-May-04 1:13
Aryadip14-May-04 1:13 
GeneralRe: How to run a CS program at client without SQL Server! Pin
tuliplanetrain16-May-04 23:28
tuliplanetrain16-May-04 23:28 
AnswerRe: How to run a CS program at client without SQL Server! Pin
mtone17-May-04 9:41
mtone17-May-04 9:41 
GeneralRe: How to run a CS program at client without SQL Server! Pin
tuliplanetrain17-May-04 15:36
tuliplanetrain17-May-04 15:36 
GeneralRe: How to run a CS program at client without SQL Server! Pin
mtone18-May-04 7:07
mtone18-May-04 7:07 
Generalspaces in SQL Server Columns (C#,VB.net) Pin
Itanium13-May-04 20:34
Itanium13-May-04 20:34 
GeneralRe: spaces in SQL Server Columns (C#,VB.net) Pin
mtone25-May-04 3:00
mtone25-May-04 3:00 
GeneralInserting special characters in SQL 2000 Pin
Anonymous13-May-04 19:37
Anonymous13-May-04 19:37 
GeneralRe: Inserting special characters in SQL 2000 Pin
Hesham Amin13-May-04 21:35
Hesham Amin13-May-04 21:35 
GeneralRe: Inserting special characters in SQL 2000 Pin
sanjucsharp13-May-04 21:39
sanjucsharp13-May-04 21:39 
GeneralRe: Inserting special characters in SQL 2000 Pin
Anonymous19-May-04 1:29
Anonymous19-May-04 1:29 
GeneralRe: Inserting special characters in SQL 2000 Pin
Rob Graham15-May-04 2:54
Rob Graham15-May-04 2:54 
GeneralEmbarcadero Rapid SQL Pin
Nino_113-May-04 15:57
Nino_113-May-04 15:57 
GeneralRe: Embarcadero Rapid SQL Pin
mtone18-May-04 7:26
mtone18-May-04 7:26 
GeneralRow Concatenation Pin
Ruchi Gupta13-May-04 13:08
Ruchi Gupta13-May-04 13:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.