Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query - "Wrong" Data Returned

Status
Not open for further replies.

a98dsu98sad8sua

Technical User
Apr 5, 2005
70
CA
Hi all,

I am trying to use this SQL query to output the results of a questionnaire into a report:

SELECT Calls.CallID, Calls.CallTime, Calls.CallDate, Calls.CallDuration, Calls.CustomerName, Calls.CustomerNumber, Calls.AddedBy, Calls.FromComputer, Campaigns.CampaignName, Contracts.ContractName, Sections.SectionName, Managers.ManagerName, Staff.StaffName, Questions.Title, MonitoringTypes.MonitoringType, Responses.ResponseName
FROM (Sections INNER JOIN (Managers INNER JOIN (Contracts INNER JOIN ((Campaigns INNER JOIN (Responses INNER JOIN Questions ON Responses.ResponseTypeID = Questions.ResponseTypeID) ON Campaigns.CampaignID = Questions.CampaignID) INNER JOIN Staff ON Campaigns.CampaignID = Staff.CampaignID) ON Contracts.ContractID = Staff.ContractID) ON Managers.ManagerID = Staff.ManagerID) ON Sections.SectionID = Questions.SectionID) INNER JOIN (MonitoringTypes INNER JOIN Calls ON MonitoringTypes.MonitoringTypeID = Calls.MonitoringTypeID) ON Staff.StaffID = Calls.StaffID;

but the data it is returned is wrong! It has put for example both responses as an answer for a question, for example:

Is this a question? - Yes
Is this a question? - No

Obviously, it's only supposed to output the right one, but it seems to be printing the choices instead.

Sorry I can't explain it any more than that it is hard!

Any suggestions?

T
 
Without knowing your table structures (other than what can be deduced from the SQL) its difficult to say what the problem may be.

Just as a guess, I would conclude that table Responses contains all possible responses to the question so of course all of them are being listed. You would need either a table containing only the response that was given OR some field in the Responses table that distinguishes which of the available responses was selected.
 
This works:

SELECT [Staff.StaffName] AS StaffName, [Calls.CallTime] AS CallTime, [Calls.CallDate] AS CallDate, [Questions.Title] AS Title, [Responses.ResponseName] AS Response, [Calls.CallID] AS CallID, [Calls.CallDuration] AS Duration, [Calls.CustomerName] AS CustomerName, [Calls.CustomerNumber] AS CustomerNumber, [Calls.AddedBy] AS AddedBy, [Calls.FromComputer] AS ComputerName, [Managers.ManagerName] AS Manager, [Sections.SectionName] AS [Section], [Contracts.ContractName] AS Contract, [Campaigns.CampaignName] AS Campaign, [MonitoringTypes.MonitoringType] AS MonitoringType
FROM (Managers INNER JOIN (Contracts INNER JOIN Staff ON Contracts.ContractID=Staff.ContractID) ON Managers.ManagerID=Staff.ManagerID) INNER JOIN (Sections INNER JOIN (Responses INNER JOIN ((Campaigns INNER JOIN Questions ON Campaigns.CampaignID=Questions.CampaignID) INNER JOIN (MonitoringTypes INNER JOIN (Calls INNER JOIN Sessions ON Calls.CallID=Sessions.CallID) ON MonitoringTypes.MonitoringTypeID=Calls.MonitoringTypeID) ON Questions.QuestionID=Sessions.QuestionID) ON Responses.ResponseID=Sessions.ResponseID) ON Sections.SectionID=Questions.SectionID) ON Staff.StaffID=Calls.StaffID;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top