Results 1 to 39 of 39

Thread: Inner Join?

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    375

    Inner Join?

    Hey guys,

    Im using a string sql code to get the average of each client i have. THe code is below:

    VB Code:
    1. If cbClient.Text <> "<ALL>" Then
    2.                 strSql = "SELECT name, value as average FROM (" & vbCrLf
    3.                 strSql = strSql & "Select '" & cbClient.Text & "' as [Name], AVG([" & cbClient.Text & "]" & ".Value) as [Value] from "
    4.                 strSql = strSql & "[" & cbClient.Text & "]" & " where [" & cbClient.Text & "].Date Between #" & mindate & "# And #" & maxdate & "# " & vbCrLf
    5.                 strSql = strSql & ");"
    6.             Else
    7.                 strSql = "SELECT name, value as average FROM (" & vbCrLf
    8.                 Dim FILENAME As String
    9.                 For i = 0 To schemaTable.Rows.Count - 1
    10.                     FILENAME = schemaTable.Rows(i).Item("TABLE_NAME")
    11.                     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
    12.                         If IsFirstSubquery Then
    13.                             IsFirstSubquery = False
    14.                         Else
    15.                             strSql = strSql & "union " & vbCrLf
    16.                         End If
    17.                         strSql = strSql & "Select '" & FILENAME & "' as [Name], AVG([" & FILENAME & "]" & ".Value) as [Value] from "
    18.                         strSql = strSql & "[" & FILENAME & "]" & " where [" & FILENAME & "].Date Between #" & mindate & "# And #" & maxdate & "# " & vbCrLf
    19.                     End If
    20.                 Next i
    21.                 strSql = strSql & ");"
    22.             End If
    23.             cmd = New OleDbCommand(strSql, con)
    24.             dr = cmd.ExecuteReader
    25.             'The control datagridview does not have the items property, but it has the datasource property
    26.             'then we can use it to use that we need to assign the results of the query to an
    27.             'arraylist, for instance, then assing this arraylist to the datasource property of
    28.             'the datagrid
    29.             Dim QueryResult As New ArrayList
    30.             While dr.Read
    31.                 Dim dummy As New Average
    32.                 dummy.Name = dr("name")
    33.                 If Not IsDBNull(dr("average")) Then
    34.                     dummy.Average = dr("average")
    35.                 Else
    36.                     dummy.Average = "0"
    37.                 End If
    38.                 QueryResult.Add(dummy)
    39.             End While
    40.             dgvAverage.DataSource = QueryResult
    41.             'set the "average" column display order as the second column
    42.             Me.dgvAverage.Columns("average").DisplayIndex = 1
    43.             'average being the index of the column
    44.             Me.dgvAverage.Columns("average").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
    45.             'set the "name" column display order as the first column
    46.             Me.dgvAverage.Columns("name").DisplayIndex = 0
    47.             'name being the index of the column
    48.             Me.dgvAverage.Columns("name").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
    49.             dr.Close()
    50.             cmd.Dispose().
    51.  Private Class Average
    52.         Private _name As String
    53.         Private _average As String
    54.         Public Property Name() As String
    55.             Get
    56.                 Return _name
    57.             End Get
    58.             Set(ByVal value As String)
    59.                 _name = value
    60.             End Set
    61.         End Property
    62.         Public Property Average() As String
    63.             Get
    64.                 Return _average
    65.             End Get
    66.             Set(ByVal value As String)
    67.                 _average = Math.Round(Double.Parse(value)).ToString
    68.                 If _average.Length < 16 Then
    69.                     Dim strTemp As String = String.Empty
    70.                     Dim chr As Char() = _average.ToCharArray
    71.                     For i As Integer = chr.Length - 1 To 0 Step -1
    72.                         If (chr.Length - i) Mod 3 = 0 And i <> 0 Then
    73.                             strTemp = "," & chr(i) & strTemp
    74.                         Else
    75.                             strTemp = chr(i) & strTemp
    76.                         End If
    77.                     Next
    78.                     _average = strTemp
    79.                 End If
    80.             End Set
    81.         End Property
    82.  
    83.     End Class

    My result table looks like this:
    name average
    aa 193,275
    ar 67,180
    at 43,716
    au 65,468

    I also have another table that is called cd_clients that look like this:
    name cy tax fee retro
    aa USD No 1.50% 0.00%
    ar USD No 1.50% 0.00%
    at USD No 1.50% 0.00%
    au USD No 1.50% 0.00%


    To get in my final query all of this data together should i add a inner join to my string sql?
    What i want is this:
    name average cy tax fee retro
    aa 193,275 USD No 1.50% 0.00%
    ar 67,180 USD No 1.50% 0.00%
    at 43,716 USD No 1.50% 0.00%
    au 65,46 USD No 1.50% 0.00%

    thx in advance for the help
    Last edited by super_nOOb; Dec 11th, 2006 at 10:15 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