SQL Server Performance

SQL select statement help please

Discussion in 'SQL Server 2005 General Developer Questions' started by Aka, Mar 16, 2012.

  1. Aka New Member

    Helooo..

    I am new to programming in general and am currently in the process of devolving a asp page that connects to a database in access. I have the following line of code but it does not seem to work.

    strSQL = "SELECT People.Forename, People.Surname, Address.Address Type, Address.Street Address, Address.City, Address.County, Address.Postcode FROM People, Address;"

    I have also tried

    strSQL = "SELECT People.Forename, People.Surname, Address.Address_Type, Address.Street_Address, Address.City, Address.County, Address.Postcode FROM People, Address;"

    Can someone tell me what I am doing wrong no doubt it will be something silly.
  2. FrankKalis Moderator

    Welcome to the forum!
    It would have been beneficial if you had posted what error you received. Now, this is more or less guesswork as we're more of SQL Server people here than MS Access. In SQL Server the syntax FROM TableA, TableB is a CROSS JOIN which is the cartesian product of the rows from the tables in the JOIN. If you happen to have 10 rows in TableA and 10 rows in TableB your result set will contain 100 rows and this may or may not be what you want. Usually you would write something more like
    Code:
    SELECT
        People.Forename,
        People.Surname,
        Address.Address Type,
        Address.Street Address,
        Address.City,
        Address.County,
        Address.Postcode
    FROM
        People
        JOIN
        ADDRESS ON People.KeyColumn(s) = Address.KeyColumn(s);
    
    But then again, some hints about the error you receive would be good. :)

Share This Page