473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Using format date with multiple date fields in Query to display in one field

547 512MB
I have two dates in my tblAcquire table.
It is called OrderDate and Invoicedate.

I would like to display the month from the "Orderdate" field but if that is unavailable, then use the "Invoicedate" or vice versa, to determine the month from the same record(row).
ie if MonthOrder isnull then display Monthinvoice and vice versa.
My code in the Query displays one date only currently correctly
Expand|Select|Wrap|Line Numbers
  1. MonthOrder: Format([OrderDate],"mm/yyyy")
  2. MonthInvoice: Format([Invoicedate]"mm/yyyy")
  3.  
  4. Month: IIf([MonthOrder] Is Null Or [MonthOrder]="",[MonthInvoice]) Or IIf([MonthInvoice] Is Null Or [MonthInvoice]="",[MonthOrder])
  5.  
It does not add the month in the new field - only add -1
I need to filter on the Month field, in the criteria

Any suggestions please?
Feb 3 '14 #1
4 1257
Seth Schrock
2,965 Expert 2GB
You might be running into problems because Month is a reserved name. Also, from my research, you can't use the alias name in the WHERE clause directly. However, you can do it as a sub query.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM
  2. (SELECT Format(OrderDate, "mm/yyyy") As MonthOrder
  3. , Format(InvoiceDate, "mm/yyyy") As MonthInvoice
  4. , IIF(MonthOrder Is Null, MonthInvoice, MonthOrder) As EntryMonth
  5. FROM tableName)
  6. WHERE EntryMonth > #2/3/2013#
This works because the main query is receiving the information using the aliases from the subquery. This might have a performance impact however.
Feb 3 '14 #2
neelsfer
547 512MB
This code add the Month from either "MonthOrder" or "MonthInvoice" if one is blank but not when both Months are displayed. In this case i would like the "monthOrder" to show up as default.
Expand|Select|Wrap|Line Numbers
  1. Months: IIf([MonthOrder] Is Null Or [MonthOrder]="",[MonthInvoice],IIf([MonthInvoice] Is Null Or [MonthInvoice]="",[MonthOrder]))
Suggestions
Feb 3 '14 #3
neelsfer
547 512MB
Thx Seth. I think i got it working by pure trial and error and accident now, with this code.
Expand|Select|Wrap|Line Numbers
  1. Months: IIf([MonthOrder] Is Null Or [MonthOrder]="",[MonthInvoice],IIf([MonthInvoice] Is Null Or [MonthInvoice]="",[MonthOrder],IIf([MonthOrder] Is Not Null,[MonthOrder])))
Feb 3 '14 #4
Seth Schrock
2,965 Expert 2GB
Okay. Glad you got it working. I didn't pay much attention to your iif statement as I was focusing on using the alias in the WHERE clause.
Feb 3 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bernd Lambertz | last post by:
I have a problem with bcp and format files. We changed our databases from varchar to nvarchar to support unicode. No problems so fare with that. It is working fine. But now I need a format...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
1
by: Dominic Marks | last post by:
Hi, (I apologise if this is the wrong list, I haven't posted to a postgresql.org mailing list before, general seemed like a good catch-all) I am trying to implement a centralised...
15
by: PMBragg | last post by:
Thank you in advance. I'm trying to pull all inventory items from December of the previous year back to 4 years for my accountant. I know this can be done, but I'm drawing a blank. I've tried; ...
2
by: LoopyNZ | last post by:
Hi, (Access 97) I'm creating a query (QRY_SUMMARY) to join a query (QRY) to itself (QRY_1). I'm returning QRY.* and selected fields from QRY_1. With each field (field_name) I return from...
4
by: S. van Beek | last post by:
Dear reader, By a Date field with Now() as default value the content of the field is date plus time. As I need a filter in a query on date only (excluding time) I invented the following...
2
by: Rahul | last post by:
Hey Guys I have a development environment, in which the whole SQL syntax is stored in the Database. So the syntax in the databse column could be "where BirthDate = '12/31/2005' and ID =...
0
by: Andre Saputra | last post by:
Dear all. I really need help for my code. im using text box to filter data in listview, heres the code reloadlistview1 "select * from sales where TANGGAL between #" & Text1.Text & "#" & _ ...
2
by: Paul Wotherspoo | last post by:
Access 2007 - I have a table containing 6 dates (date, date1, date2, etc. There are payments associated with these dates (payment1, payment 2, ect). I want to write a query that will total all...
2
by: Salesh Dayal | last post by:
My query requires a date input however when this date is outputted, it comes in a format DD/MM/YYYY however the display format is still text and not a date. i want an extension of the query...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.