Results 1 to 4 of 4

Thread: Data Read Using INNER JOIN - Column with same name but different data

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2016
    Location
    South Carolina
    Posts
    51

    Data Read Using INNER JOIN - Column with same name but different data

    Code:
    cmd = New SqlCommand("SELECT AlarmDate, OperCode, AcctNum, Name, AlarmZones, Number, ZL.Description, SC.Description  FROM " & xDateReport & " as SH " _
                                     & "INNER JOIN Subscriber.dbo.[Subscriber Data] as SD " _
                                     & "ON " _
                                     & "SH.AccountID = SD.AccountID " _
                                     & "INNER JOIN Subscriber.dbo.[Zone Lists] as ZL " _
                                     & "ON " _
                                     & "SH.AccountID = ZL.AccountID " _
                                     & "INNER JOIN MISCELLANEOUS.dbo.[Signal Codes] as SC " _
                                     & "ON " _
                                     & "SH.AlarmCode COLLATE DATABASE_DEFAULT = SC.Code " _
                                     & " where AlarmDate between '" & Fdate1 & "00:00:00' and '" & Fdate2 & "23:59:59' and AlarmZones COLLATE DATABASE_DEFAULT = LTRIM(RTRIM(Number))  order by AlarmDate ASC ", SQLConn)
    
                dr = cmd.ExecuteReader
    
    
                Do While dr.Read
                    DataGridView1.Rows.Add(Format(dr("AlarmDate")), dr("OperCode"), dr("AcctNum"), dr("Name"), dr("AlarmZones"), dr(ZL."Description"), dr(SC."Description"))
                Loop
                dr.Close()
    How can I read from selected database.table.column using INNER JOIN with same name but different data.

    Thanks

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Data Read Using INNER JOIN - Column with same name but different data

    By aliasing them...

    ZL.Description as ZoneDescription, SC.Description as SignalDescription


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2016
    Location
    South Carolina
    Posts
    51

    Re: Data Read Using INNER JOIN - Column with same name but different data

    That fixed it

    Thanks tg

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Data Read Using INNER JOIN - Column with same name but different data

    OT, if you're populating a DataGridView then you shouldn't be loading the data row by row but rather populating a DataTable and binding it. A DataTable has a Load method to which you can pass a data reader.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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