简体   繁体   English

SSRS报表的SQL查询Visual Studio查询设计器

[英]SQL Query for SSRS Report Visual Studio Query Designer

Can someone please help with an SQL Query I am facing. 有人可以帮助我面对一个SQL查询。

Currently I am using Visual Studio 2013 Query Designer for my SSRS reports and I'm trying to select Students that are enrolled at their current School. 目前,我正在将Visual Studio 2013查询设计器用于我的SSRS报表,并且试图选择在其当前学校就读的学生。 However when testing my query for a selected student, it is returning all possible schools and saying the student has attended all 317 of them which is incorrect. 但是,当测试我对所选学生的查询时,它将返回所有可能的学校,并说该学生已参加了所有317所学校,这是不正确的。 My question is how do I find the school that a student has attended/attending? 我的问题是如何找到学生上过/上过学的学校?

The query code is below: 查询代码如下:

SELECT Person.Firstname, Person.Surname, Company.Name AS School, Company.CompanyCategory, Student.StudentNumber
FROM   Student INNER JOIN
       Person ON Student.ID = Person.ID CROSS JOIN
       Company
WHERE  (Company.CompanyCategory = 'Delivery Location') AND (Student.StudentNumber = '....')

As Sandeep mentioned, you are cross joining to Company (I'm assuming this is school?). 正如Sandeep所说,您正在交叉加入Company (我假设这是学校吗?)。 You'll probably have to INNER JOIN to Company and specify a JOIN clause. 您可能必须将INNER JOIN到Company并指定一个JOIN子句。 The table Student might have CompanyID or something? Student表可能具有CompanyID或其他名称? You can JOIN that on the Company.ID . 您可以在Company.IDJOIN So the query becomes something like this: 因此查询变成了这样的东西:

SELECT Person.Firstname, Person.Surname, Company.Name AS School, Company.CompanyCategory, Student.StudentNumber
FROM   Student INNER JOIN
       Person ON Student.ID = Person.ID INNER JOIN
       --Not sure if CompanyID is the right field
       Company ON Student.CompanyID = Company.ID
WHERE  (Company.CompanyCategory = 'Delivery Location') AND (Student.StudentNumber = '....')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM