Results 1 to 39 of 39

Thread: Inner Join?

Threaded View

  1. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    375

    Re: Inner Join?

    @ bmahler- thx for the reply. Just one question. Should i change anything in the 1st select? And how can i set my dr.read to make the output in the datagrid too

    SELECT name, value as average FROM(
    Select 'aa' as [name], AVG([aa].Value) as [Value] from [aa] where [aa].Date Between #01/01/2006# And #03/31/2006#
    );

    EDIT: The sql output is looking like this:

    SELECT name, value as average FROM(
    Select 'aa' as [name], AVG([aa].Value) as [Value], cd_clients.currency, cd_clients.vat, cd_clients.mngmt_fee, cd_clients.retrocession from [aa] OUTER JOIN cd_clients on [aa].Name = cd_clients.[aa] where [aa].Date Between #01/01/2006# And #03/31/2006#
    union
    Select 'ar' as [name], AVG([ar].Value) as [Value], cd_clients.currency, cd_clients.vat, cd_clients.mngmt_fee, cd_clients.retrocession from [ar] OUTER JOIN cd_clients on [ar].Name = cd_clients.[ar] where [ar].Date Between #01/01/2006# And #03/31/2006#
    );

    And the VBCODE is this
    VB Code:
    1. strSql = "SELECT name, value as average FROM (" & vbCrLf
    2.                 Dim FILENAME As String
    3.                 For i = 0 To schemaTable.Rows.Count - 1
    4.                     FILENAME = schemaTable.Rows(i).Item("TABLE_NAME")
    5.                     If (Not FILENAME.StartsWith("~TMP")) And Not (FILENAME.StartsWith("Msys")) And Not (FILENAME.StartsWith("fx_")) And Not (FILENAME.StartsWith("pr_")) And Not (FILENAME.StartsWith("cd_")) Then
    6.                         If IsFirstSubquery Then
    7.                             IsFirstSubquery = False
    8.                         Else
    9.                             strSql = strSql & "union " & vbCrLf
    10.                         End If
    11.                         strSql = strSql & "Select '" & FILENAME & "' as [Name], AVG([" & FILENAME & "]" & ".Value) as [Value], cd_clients.currency, cd_clients.vat, cd_clients.mngmt_fee, cd_clients.retrocession from "
    12.                         strSql = strSql & "[" & FILENAME & "]" & " OUTER JOIN cd_clients on [" & FILENAME & "].Name = cd_clients.[" & FILENAME & "] where [" & FILENAME & "].Date Between #" & mindate & "# And #" & maxdate & "# " & vbCrLf
    13.                     End If
    14.                 Next i
    15.                 strSql = strSql & ");"

    Is it correct?

    And here it is where i ask for the result in the DataGrid
    VB Code:
    1. cmd = New OleDbCommand(strSql, con)
    2.             dr = cmd.ExecuteReader
    3.             Dim QueryResult As New ArrayList
    4.             While dr.Read
    5.                 Dim dummy As New Average
    6.                 dummy.Name = dr("name")
    7.                 If Not IsDBNull(dr("average")) Then
    8.                     dummy.Average = dr("average")
    9.                 Else
    10.                     dummy.Average = "0"
    11.                 End If
    12.                 QueryResult.Add(dummy)
    13.             End While
    14.             dgvAverage.DataSource = QueryResult
    15. '____________________________________________________
    16.     Private Class Average
    17.         Private _name As String
    18.         Private _average As String
    19.         Public Property Name() As String
    20.             Get
    21.                 Return _name
    22.             End Get
    23.             Set(ByVal value As String)
    24.                 _name = value
    25.             End Set
    26.         End Property
    27.         Public Property Average() As String
    28.             Get
    29.                 Return _average
    30.             End Get
    31.             Set(ByVal value As String)
    32.                 _average = Math.Round(Double.Parse(value)).ToString
    33.                 If _average.Length < 16 Then
    34.                     Dim strTemp As String = String.Empty
    35.                     Dim chr As Char() = _average.ToCharArray
    36.                     For i As Integer = chr.Length - 1 To 0 Step -1
    37.                         If (chr.Length - i) Mod 3 = 0 And i <> 0 Then
    38.                             strTemp = "," & chr(i) & strTemp
    39.                         Else
    40.                             strTemp = chr(i) & strTemp
    41.                         End If
    42.                     Next
    43.                     _average = strTemp
    44.                 End If
    45.             End Set
    46.         End Property
    47.  
    48.     End Class
    Last edited by super_nOOb; Dec 12th, 2006 at 03:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width