Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Selecting from multiple tables

Author  Topic 

GavinD1977
Yak Posting Veteran

83 Posts

Posted - 2007-04-02 : 12:10:52
Hi all.

I'm trying to select from multiple table in one select statement but i'm having problems. Here is the code i'm trying:



if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[snow_ors_additionalInfoRead]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[snow_ors_additionalInfoRead]
GO

CREATE PROCEDURE dbo.snow_ors_additionalInfoRead
@Reference int
AS
SELECT
Account.CanTravel,
Account.SEEmployee,
Account.WorkHours,
Account.DrivingLicence,
Account.CriminalConvictions,
Account.CriminalConvictionsDetails1,
Account.CriminalConvictionsDate1,
Account.CriminalConvictionsDetails2,
Account.CriminalConvictionsDate2,
Account.CriminalConvictionsDetails3,
Account.CriminalConvictionsDate3,
Application.VacancyMonitoring,
Application.VacancyMonitoringDetails
FROM Account, Application
WHERE Account.Reference = @Reference AND
Application.reference = @Reference


GO


Any help at all would be great.

thanks people.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-02 : 12:13:41
[code]SELECT
Account.CanTravel,
Account.SEEmployee,
Account.WorkHours,
Account.DrivingLicence,
Account.CriminalConvictions,
Account.CriminalConvictionsDetails1,
Account.CriminalConvictionsDate1,
Account.CriminalConvictionsDetails2,
Account.CriminalConvictionsDate2,
Account.CriminalConvictionsDetails3,
Account.CriminalConvictionsDate3,
Application.VacancyMonitoring,
Application.VacancyMonitoringDetails
FROM Account Join Application
on Account.Reference = Application.reference
Where Account.Reference = @Reference[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-04-02 : 12:13:52
Forget to join the two tables?

...
Account.Somecolumn = Application.Somecolumn?
...


************************
Life is short. Enjoy it.
************************
Go to Top of Page

GavinD1977
Yak Posting Veteran

83 Posts

Posted - 2007-04-02 : 12:16:47
hi guys.........thanks you both very much for the quick reply.

How does the SQL that dinkar has added tie in with what youve writen harsh?

Thanks again guys.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-02 : 12:19:42
I have already illustrated what Dinakar has asked by adding a join condition. Take a look at the ON part.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

GavinD1977
Yak Posting Veteran

83 Posts

Posted - 2007-04-02 : 12:21:42
OK......thats great.

thanks again guys!
Go to Top of Page
   

- Advertisement -