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
 Comparing Two Tables

Author  Topic 

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2010-12-22 : 11:58:27
I have 2 tables. Both have a commone field SyStudentID. I want to find out what how many IDs are in the SyStudent Table versus the AmPropsectPrevEduc table. I created a view:

SELECT dbo.syStudent.SSN, dbo.syStudent.LastName, dbo.syStudent.FirstName, dbo.syStudent.SyStudentId, dbo.AmProspectPrevEduc.AmCollegeID,
dbo.amPrevEduc.Code, dbo.amPrevEduc.Descrip, dbo.AmProspectPrevEduc.SyStudentID AS StudentID
FROM dbo.syStudent INNER JOIN
dbo.AmProspectPrevEduc ON dbo.syStudent.SyStudentId = dbo.AmProspectPrevEduc.SyStudentID LEFT OUTER JOIN
dbo.amPrevEduc ON dbo.AmProspectPrevEduc.AmPrevEducID = dbo.amPrevEduc.amPrevEducID INNER JOIN
dbo.AdTerm ON dbo.amPrevEduc.UserID = dbo.AdTerm.Userid
WHERE (dbo.AdTerm.Code = 'xfer')

And I was trying to join the view to the SyStudent table to get the comparison.

select
dbo.[MB_TransferStudent].StudentID
from
dbo.[MB_TransferStudent] left outer join
dbo.SyStudent on
dbo.[MB_TransferStudent].StudentID=dbo.systudent.SyStudentID
where
dbo.[MB_TansferStudent].StudentID=dbo.systudent.SyStudentID

But the second query does not run.

Any assistance would be greatly appreciated.

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-12-22 : 22:41:12
Is the view name is MB_TransferStudent ?

How many records you are getting from view ?


though may not be cause but I feel that where condition is not required.
quote:

select
dbo.[MB_TransferStudent].StudentID
from
dbo.[MB_TransferStudent] left outer join
dbo.SyStudent on
dbo.[MB_TransferStudent].StudentID=dbo.systudent.SyStudentID
where dbo.[MB_TansferStudent].StudentID=dbo.systudent.SyStudentID

Go to Top of Page
   

- Advertisement -