Solved

How di I modify a sql query in Access?

Posted on 2008-10-10
8
227 Views
Last Modified: 2012-05-05
Hi,
I have a query created in Access 2000 called qsel_SurveyDetails.
which returns a table. (see attachment)
I want to replace the ObjectRef column
With a column called  ref_num from another table called call_req.
When I add the new table in the Design View and then run the query it returns no data.
How can I replace the ObjectRef column with the call_req.ref_num column using the Design view or other method?
Thanks


.......OK to summarize the question.
How can I alter the code below to replacethe ObjectRef column
with the ref_num column from the call_req table........
 
SELECT survey.id, survey.sym AS SurveyName, CvrtFromUnixTime([survey]![last_mod_dt]) AS LastModDate, IIf(IsNull([c_first_name]),[c_last_name],[c_last_name] & ", " & [c_first_name]) AS LastModBy, survey.description, survey.comment_label, survey.nx_comment, [survey]![object_type]+":"+CStr([survey]![object_id]) AS ObjectRef, OBTypeToWord([object_type]) AS OBType, survey_question.sequence, survey_question.id, survey_question.txt, survey_answer.selected, IIf([survey_answer].[selected],1,0) AS CountOfAnswer, IIf(([response]=0 And [mult_resp_flag]=0),1,0) AS CountOfBlankAns, IIf([survey_answer].[selected],"*","") AS ChoiceSign, survey_answer.sequence, survey_answer.id, survey_answer.txt, CDate([Forms]![Report Selector]![StartDate]) AS FromDate, CDate([Forms]![Report Selector]![EndDate]) AS ToDate, survey_question.qcomment_label, survey_question.qcomment
FROM (survey INNER JOIN (survey_question INNER JOIN survey_answer ON survey_question.id = survey_answer.own_srvy_question) ON survey.id = survey_question.owning_survey) INNER JOIN ctct ON survey.last_mod_by = ctct.id
WHERE (((survey.sym) Like [Forms]![Report Selector]![cboSurvey]) AND ((survey.last_mod_dt)>=[Forms]![Report Selector]![txtUnixStart] And (survey.last_mod_dt)<=[Forms]![Report Selector]![txtUnixEnd]))
ORDER BY survey.id, survey.sym, survey_question.sequence, survey_answer.sequence

Open in new window

AccessReport-incident-numberV2.doc
0
Comment
Question by:blossompark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22686058
what field(s) relate survey (or other tables listed) to ObjectRef?

Knowing that, I can write you a query.
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 22686144
You need to join the call_req table.  I didn't see from your screenshots how you tried to join call_req but you might have joined it by the wrong columns.
0
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22686162
Yeah, the call_req table -- that's the one I meant.  What field in it relates to a field in Survey or one of the other tables you already have?
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

Author Comment

by:blossompark
ID: 22686208
Hi DanielWilson
 The ahd.survey.object_id in the survey table. references the ahd.call_req.id. The ahd.call_req table contains the ref_num column.

ahd is the name of the database on the underlying sql server 2000
0
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22686317
OK, I've joined in call_req on a LEFT JOIN so that missing call_req records won't eliminate Survey records.  That may have been the problem w/ the join the designer created for you.  If you want to get rid of the ObjectRef field, just delete it from the query.

 
SELECT survey.id, survey.sym AS SurveyName, CvrtFromUnixTime([survey]![last_mod_dt]) AS LastModDate, 
	IIf(IsNull([c_first_name]),[c_last_name],[c_last_name] & ", " & [c_first_name]) AS LastModBy, 
	survey.description, survey.comment_label, survey.nx_comment, 
	[survey]![object_type]+":"+CStr([survey]![object_id]) AS ObjectRef, 
	OBTypeToWord([object_type]) AS OBType, survey_question.sequence, survey_question.id, survey_question.txt, survey_answer.selected, 
	IIf([survey_answer].[selected],1,0) AS CountOfAnswer, IIf(([response]=0 And [mult_resp_flag]=0),1,0) AS CountOfBlankAns, 
	IIf([survey_answer].[selected],"*","") AS ChoiceSign, survey_answer.sequence, survey_answer.id, survey_answer.txt, 
	CDate([Forms]![Report Selector]![StartDate]) AS FromDate, CDate([Forms]![Report Selector]![EndDate]) AS ToDate, 
	survey_question.qcomment_label, survey_question.qcomment,
	Call_req.Ref_Num
FROM (survey INNER JOIN 
	(survey_question INNER JOIN survey_answer ON survey_question.id = survey_answer.own_srvy_question) ON survey.id = survey_question.owning_survey) INNER JOIN 
	ctct ON survey.last_mod_by = ctct.id Left Join call_req on survey.object_id = call_req.id
WHERE (((survey.sym) Like [Forms]![Report Selector]![cboSurvey]) AND ((survey.last_mod_dt)>=[Forms]![Report Selector]![txtUnixStart] And (survey.last_mod_dt)<=[Forms]![Report Selector]![txtUnixEnd]))
ORDER BY survey.id, survey.sym, survey_question.sequence, survey_answer.sequence

Open in new window

0
 

Author Comment

by:blossompark
ID: 22686450
Hi DanielWilson
ran the above and got;
syntax error missing operator in query expression
"survey.last_mod_by = ctct.id Left Join call_req on survey.object_id = call_req.id"
0
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 500 total points
ID: 22686488
Well, Access is always big on parentheses.  Let's try this:


SELECT survey.id, survey.sym AS SurveyName, CvrtFromUnixTime([survey]![last_mod_dt]) AS LastModDate, 
        IIf(IsNull([c_first_name]),[c_last_name],[c_last_name] & ", " & [c_first_name]) AS LastModBy, 
        survey.description, survey.comment_label, survey.nx_comment, 
        [survey]![object_type]+":"+CStr([survey]![object_id]) AS ObjectRef, 
        OBTypeToWord([object_type]) AS OBType, survey_question.sequence, survey_question.id, survey_question.txt, survey_answer.selected, 
        IIf([survey_answer].[selected],1,0) AS CountOfAnswer, IIf(([response]=0 And [mult_resp_flag]=0),1,0) AS CountOfBlankAns, 
        IIf([survey_answer].[selected],"*","") AS ChoiceSign, survey_answer.sequence, survey_answer.id, survey_answer.txt, 
        CDate([Forms]![Report Selector]![StartDate]) AS FromDate, CDate([Forms]![Report Selector]![EndDate]) AS ToDate, 
        survey_question.qcomment_label, survey_question.qcomment,
        Call_req.Ref_Num
FROM ((survey INNER JOIN 
        (survey_question INNER JOIN survey_answer ON survey_question.id = survey_answer.own_srvy_question) ON survey.id = survey_question.owning_survey) INNER JOIN 
        ctct ON survey.last_mod_by = ctct.id) Left OUTER Join call_req on survey.object_id = call_req.id
WHERE (((survey.sym) Like [Forms]![Report Selector]![cboSurvey]) AND ((survey.last_mod_dt)>=[Forms]![Report Selector]![txtUnixStart] And (survey.last_mod_dt)<=[Forms]![Report Selector]![txtUnixEnd]))
ORDER BY survey.id, survey.sym, survey_question.sequence, survey_answer.sequence

Open in new window

0
 

Author Closing Comment

by:blossompark
ID: 31504974
Fantastic DanielWilson!!!!!!!!!!!!!!!!!!!!!!! The weekend starts here!!!!
Thanks that is absolutely brilliant... Made my day bigtime!!!!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to use three values with DATEDIFF 3 42
IIF in access query 19 39
Return Rows as per Quantity of Columns Value In SQL 6 27
compare date to getdate() 8 16
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question