Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Access query for SQL database to select records

Posted on 2008-11-13
13
Medium Priority
?
649 Views
Last Modified: 2012-05-05
We use Access to query a SQL database that is back end of our accounting software for reports.  In SQL there is a table--History that has shows payroll deductions.  A record for one employee's check will show the deductions as fields--ded1, ded2, ded3 etc.  Numbers are used as codes in these fields to indicate what type of deduction such as 401 k.  401k deduction uses "29".  However, that 29 will appear in different deduction fields depending on the employee--so that employee 1 might have "29" in ded1 and employee 2 might have "29" in ded2.  We want to query this table to return all employees that have 29 in any of these fields and no other employees.  When we insert 29 in the grid in Access select query design in all (ded1, ded2, etc.) this obviously does not work.  I do not have sophisticated Access skills--any help on how to design this would be appreciated.
0
Comment
Question by:dur2348
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 5

Expert Comment

by:funnymanmike
ID: 22951481
this should basically return what your looking for.
select * from <tablename> where <field1> = 29 or <field2> = 29

Open in new window

0
 

Author Comment

by:dur2348
ID: 22951661
If I want to query for "29" or "3",  can I add an or statement?
0
 
LVL 5

Expert Comment

by:funnymanmike
ID: 22951872
you can add as many or statments as you want.

if your checking 2 fields for two possible values then you can go with this.
select * from <tablename> where <field1> = 29 or <field2> = 29 or <field1> = 3 or <field2> = 3

Open in new window

0
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 

Author Comment

by:dur2348
ID: 22952058
Is this to be used in SQL database or Access or does it matter?  If in Access would it be inserted in SQL view of query?
0
 
LVL 5

Assisted Solution

by:funnymanmike
funnymanmike earned 800 total points
ID: 22952101
remember sql is a language, ms msql 2003, access, sybase are all management suits. 90% of sql commands work in all, some have additional features.

you can use it in SQL, and you should be able to use it in access if your connected to SQL properly.

0
 
LVL 41

Expert Comment

by:Sharath
ID: 22953108
Provide some sample set in History table.
0
 

Author Comment

by:dur2348
ID: 22953672
Sample set attached.
sample.pdf
0
 
LVL 41

Assisted Solution

by:Sharath
Sharath earned 400 total points
ID: 22954350
Where is the employee information is there? WHat is the expected output? If you can provide more details, its easy to write the query soon.
0
 

Author Comment

by:dur2348
ID: 22959199
I have attached another sample with two rows referring to two employees.  These are complete rows from table with dummy social security numbers and names.  You can see there are several fields for deductible codes and amounts.  We want to query employees that have 29 or 3 in any of the deductible code fields and the amounts in the corresponding deductible amount fields and we want to sum the total of the amount fields for each employee for whatever period of time we select by payend date.  I hope this is clear enough.  If not, please ask for more information.  Thanks for the help.
SAMPLE2.pdf
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 800 total points
ID: 22960480
Perhaps something like the attached.
sum-ded.txt
0
 

Author Comment

by:dur2348
ID: 22960721
I have used a nested if statement in Access query to return values for employees on a line by line basis.  The if statement has a limitation of 7 clauses that can be nested but so far we have only used 7 of the 10 deduction fields.  After designing first query I designed second query based on first to sum the values for each employee.  I was hoping for a more efficient method and one that would handle all 10 fields.  I will try awking00 suggestion.
0
 

Accepted Solution

by:
dur2348 earned 0 total points
ID: 23305459
I am sorry not to post something sooner, but I have not been able to get back to this problem to try to use awking00's suggestion.  I am closing the question and splitting the points between experts.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Among the most obnoxious of Exchange errors is error 1216 – Attached Database Mismatch error of the Jet Database Engine. When faced with this error, users may have to suffer from mailbox inaccessibility and in worst situations, permanent data loss.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

580 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