Link to home
Start Free TrialLog in
Avatar of ca1358
ca1358

asked on

Fromating Fields

I including a Database with a query.  I need the query to do the following:
1.       Crte_DTTM-Format to be only Date
2.      Ver_NUM-If equal 1 the append AO
 If equal 2 the append GN
If equal 3 the append GO
If equal 4 the append CO
If equal 5 the append GNII
If equal 6 the append GNA
Thank you in Advance.
FormatDB.mdb
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

This looks more like a statement or work than a request for help.

Can you post your query that you have now, and perhaps explain what you've tried? The experts are here to help YOU do your job - not do it for you.
Avatar of Phillip Burton
Phillip Burton

I have no real idea as to what you are asking.

However, the answer to part 2 seems to be:

CHOOSE(Ver_NUM,"AO","GN","GO","CO","GNII","GNA")
To help with your query:

You can format a DateTime field to show the Date portion only by using the Format function:

SELECT Field1, Format(YourDateField, "mm-dd-yyyy") AS FormattedDate FROM YourTable

You can also use nested IIF statements, or the Switch method, to show different values depending on the value in a field. For example:

SELECT Field1, IIF(Field2='AO', 'A', IIF(Field2='AB', 'B'), 'C') AS SomeField FROM SomeTable

To use Switch:

SELECT Field1, Switch(Field2="AO", "A", Field2="AB", "B", Field2="AC", "C") AS SomeField FROM SomeTable
Avatar of ca1358

ASKER

I included the sample database with the queries that I am having problems with.  Name of Database is FormatDB.mdb

I have formated 200 fields, these two fields I am troubling with.  So just want some help Formating these two fields.
ASKER CERTIFIED SOLUTION
Avatar of Michael Carrillo
Michael Carrillo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For the date field you just needed to change the property to display the format as short date.
My answer is shorter - use the Choose function.
Avatar of ca1358

ASKER

Thank you for your Help .
As I re-read your request were you asking to update the field
Ver_Num to the values listed or did you
mean [Ver_Num] + Value as in
1AO
2CO
3GN
etc.
I don't recommend formatting Date fields in queries unless you are exporting the query as a csv or to excel.  It is best to format dates where they are displayed on reports or forms.

In a query if you need only the date part of a datetime field and you want the field to retain its property as a date so you can still sort it like a date or compare it to other dates, then use the DateValue() function.  The Format() function suggested by Scott actually turns a date into a string so it no longer sorts like a date or compares like a date although it is the function of choice when formatting is required due to its options.

As an example 1/1/2014 will sort BEFORE 1/2/2013 if the field is a string data type but AFTER if the field is a date data type.  Strings are processed character by character, left to right where as numeric fields (such as a date) are  aligned at the decimal point and sorted by order of magnitude so negative numbers sort descending first followed by positive numbers ascending.