Solved

query access database..

Posted on 2006-07-04
8
389 Views
Last Modified: 2012-06-27
Hi Experts,

I am pretty new to access database and my database got one table called salesinfo..

I need to query this table and i had hard time in doing so.

In sql server we had query analyser and enterprise manager so we can select table and can write query so it will display the result of the query in a grid..

In access i have seen only 2 options 1)Create query in Design view
                                                    2)Create query by using wizard..

Tottaly lost...

Secondly  one of my table field is PrintDate

                                                                       PrintDate
                                                                       09/11/2006
                                                                       11/09/2006

Since my user workstation dateformat can vary like  DD-MM-YYYY , MM-DD-YYYY.

I need to fetch all the 2006 records, so query need to omit for 09/11/ -- need check yyyy is 2006 or not if yes display
the result in a grid ..

How should i write a query and what is the query for the above mentioned scenario..





0
Comment
Question by:nyee84
8 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17040441
U can use functions like YEAR

select  * from yourtable where Year(PrintDate) = 2006

0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 100 total points
ID: 17040446
If u have a form which is bounded to the table

u can use Form_Current to determine this

say u had a field called PrintDate on your form and a checkbox called chkBox

private sub Form_Current()
    if year(printdate) = 2006 then chkBox.Value = True else chkBox.Value = False
end sub



Now what does 2006 refer to, current year? in that case, use Now()
e.g.
year(Now()) returns 2006

private sub Form_Current()
    if year(printdate) = year(Now()) then chkBox.Value = True else chkBox.Value = False
end sub


0
 
LVL 14

Assisted Solution

by:bluelizard
bluelizard earned 50 total points
ID: 17040447
1)
well, if you write the query in the design view, and then switch to "datasheet view" (by clicking on the top left icon or by selecting the menu item "query > run"), the results are indeed shown in a grid, i.e., like a table. is that what you mean?

so, for writing "normal" queries, the design view is probably the method of choice.

2)
is PrintDate a text field or a date field?  how should the query decide when to interprete it as dd-mm and when as mm-dd?

3)
what's the goal of your query? list all rows that have print date other than 2006?


--bluelizard
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 35

Accepted Solution

by:
Raynard7 earned 150 total points
ID: 17040454
If you go to the query browser - it has an option to have a visual query creator or to select SQL and write in teh query yourself.

Go to design view - on left of the tool bar there is a drop down list - there are three things on it - select SQL.

if PrintDate is a date field you can use rockiroads solution or you can use
select  * from yourtable where PrintDate > dateserial(2006,01,01)
If you use dateserial it creates the date in order that is specified by the dateserial function which is not date setting specific.
0
 
LVL 3

Assisted Solution

by:atherh
atherh earned 100 total points
ID: 17040745
Put In Module
===================

Global Const JetDateTimeFmt = "\#mm\/dd\/yyyy hh\:nn\:ss\#;;;\N\u\l\l"
Global Const JetDateFmt = "\#mm\/dd\/yyyy\#;;;\N\u\l\l"
Global Const JetTimeFmt = "\#hh\:nn\:ss\#;;;\N\u\l\l"


Go to design view - on left of the tool bar there is a drop down list - there are three things on it - select SQL.

============
'If you are passing from form

select  * from yourtable where Year(PrintDate)=" & Year(Format$(CboDate, JetDateTimeFmt))

other wise with rockiroads solution u can try in quote

select  * from yourtable where Year(PrintDate) = '2006'
0
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 100 total points
ID: 17041538
Open the Query Builder using Create Query in Design View.  You can then eitehr

1) Select the Table (or Tables) that you wnat to use in the query, then click Done
    then select the fields that you want to use from that (those) table(s)
    Then click the Red ! on the tool bar, to execute the query

2)  do NOT seledt any tables, but simple click the Done button on the Select Table dialog
     then click on the button labelled SQL (immediately below the File Menu item on the Menu bar.
     Now you can enter the full SQL for whatever query you want to execute.  Then click the red ! to execute the query

eiterh way, when you close the Querry builder, you will be asked if you want to save the Query that you have just built.  If you choose to save it, you can then supply a Name for the saved query.

AW
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17041585
Here is a tutorial for u
The site may be useful for u as it contains other info as well regarding Access
http://www.functionx.com/access/Lesson16.htm
0
 

Author Comment

by:nyee84
ID: 17042175
Hi Experts,

Thanks for all the comments..

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

735 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