SQL select statement help please | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

SQL select statement help please

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.
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. :)
]]>

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |