473,397 Members | 2,084 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,397 software developers and data experts.

MS Query - STANDARD DATE to YEAR-MONTH

Hi,
I´m no superuser when it comes to MS Access. So I use MS Query to pull
out info from an SQL database to Excel.

I have a tabel containing different "titles" or "colums".
One contains a date. When executing the query. And getting the data to
Excel the date is in the standard date format (YYYY-MM-DD).

I would like to get this data in a different format directly from/in
the query.
I need it in the following format: YYYY-MM

I am using a standard "Select command".
SELECT INVENTTRANS.DATEFINANCIAL
Inventtrans = the table
Datefinancial = titel/column

Hopefully someone can help me in this.

/Dani
Nov 12 '05 #1
5 16441
Dani,

You can probably use funtions in your ms sql query... (click the sql button
if necessary)

select year(INVENTTRANS.DATEFINANCIAL) & '-' &
month(INVENTTRANS.DATEFINANCIAL) as dfDate from INVENTTRANS

That would return a string/character type so you might need to modify the
format of the column on the sheet for sorting and stuff.

Good luck!


"Dani" <da**@papegoja.net> wrote in message
news:78**************************@posting.google.c om...
Hi,
I´m no superuser when it comes to MS Access. So I use MS Query to pull
out info from an SQL database to Excel.

I have a tabel containing different "titles" or "colums".
One contains a date. When executing the query. And getting the data to
Excel the date is in the standard date format (YYYY-MM-DD).

I would like to get this data in a different format directly from/in
the query.
I need it in the following format: YYYY-MM

I am using a standard "Select command".
SELECT INVENTTRANS.DATEFINANCIAL
Inventtrans = the table
Datefinancial = titel/column

Hopefully someone can help me in this.

/Dani

Nov 12 '05 #2
Umm... you may have trouble with that on second thought....

Try this instead...

SELECT convert(varchar(4),year(INVENTTRANS.DATEFINANCIAL) ) + '-' +
convert(varchar(2),month(INVENTTRANS.DATEFINANCIAL )) AS 'dfDate'
FROM INVENTTRANS
"Jerry Boone" <je*************@gomaps.com> wrote in message
news:K8************@newssvr24.news.prodigy.com...
Dani,

You can probably use funtions in your ms sql query... (click the sql button if necessary)

select year(INVENTTRANS.DATEFINANCIAL) & '-' &
month(INVENTTRANS.DATEFINANCIAL) as dfDate from INVENTTRANS

That would return a string/character type so you might need to modify the
format of the column on the sheet for sorting and stuff.

Good luck!


"Dani" <da**@papegoja.net> wrote in message
news:78**************************@posting.google.c om...
Hi,
I´m no superuser when it comes to MS Access. So I use MS Query to pull
out info from an SQL database to Excel.

I have a tabel containing different "titles" or "colums".
One contains a date. When executing the query. And getting the data to
Excel the date is in the standard date format (YYYY-MM-DD).

I would like to get this data in a different format directly from/in
the query.
I need it in the following format: YYYY-MM

I am using a standard "Select command".
SELECT INVENTTRANS.DATEFINANCIAL
Inventtrans = the table
Datefinancial = titel/column

Hopefully someone can help me in this.

/Dani


Nov 12 '05 #3
Hi Jerry!
This workt great!!! You rock! Thanks a million! If you lived in Sweden I
would have sent you a bottle of wine!

Maybe you could help perfect the report?
I would like to get MS Query to return the same date in "weeks".
2003-01-01 would be week 1.

I don´t want to have to do this in Excell. I´m pulling the date directly
into a pivottable. And would like the whole report to be self updatable.

Is this possible?

Best regards
/Dani

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4
This should work for that....

SELECT datename(wk, INVENTTRANS.DATEFINANCIAL)) AS 'dfWeek'
FROM INVENTTRANS

Glad I could help, thanks for the nice comments.

:)

The thing to remember is that you are sending a query to sql server. It
doesn't matter so much as what application is working with sql (msquery,
access, et..). The thing you need is a good sql server query reference. If
you have access to the sql server cdrom you can install the "Books OnLine"
and you would be surprised at how much information is in there. You will
mainly want to search the T-Sql section since this type of code is Transact
Sql.

Good luck!


"Papegoja" <an*******@devdex.com> wrote in message
news:3f*********************@news.frii.net...
Hi Jerry!
This workt great!!! You rock! Thanks a million! If you lived in Sweden I
would have sent you a bottle of wine!

Maybe you could help perfect the report?
I would like to get MS Query to return the same date in "weeks".
2003-01-01 would be week 1.

I don´t want to have to do this in Excell. I´m pulling the date directly
into a pivottable. And would like the whole report to be self updatable.

Is this possible?

Best regards
/Dani

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #5
Oh yeah...

And if you want it to print the name "Week" in front do this...

SELECT 'Week ' + datename(wk, INVENTTRANS.DATEFINANCIAL)) AS 'dfWeek'
FROM INVENTTRANS
"Jerry Boone" <je***@gomaps.com.nospam> wrote in message
news:_m***************@newssvr23.news.prodigy.com. ..
This should work for that....

SELECT datename(wk, INVENTTRANS.DATEFINANCIAL)) AS 'dfWeek'
FROM INVENTTRANS

Glad I could help, thanks for the nice comments.

:)

The thing to remember is that you are sending a query to sql server. It
doesn't matter so much as what application is working with sql (msquery,
access, et..). The thing you need is a good sql server query reference. If you have access to the sql server cdrom you can install the "Books OnLine"
and you would be surprised at how much information is in there. You will
mainly want to search the T-Sql section since this type of code is Transact Sql.

Good luck!


"Papegoja" <an*******@devdex.com> wrote in message
news:3f*********************@news.frii.net...
Hi Jerry!
This workt great!!! You rock! Thanks a million! If you lived in Sweden I
would have sent you a bottle of wine!

Maybe you could help perfect the report?
I would like to get MS Query to return the same date in "weeks".
2003-01-01 would be week 1.

I don´t want to have to do this in Excell. I´m pulling the date directly
into a pivottable. And would like the whole report to be self updatable.

Is this possible?

Best regards
/Dani

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: vnl | last post by:
I'm trying to run a SQL query but can't find any records when trying to select a certain date. Here's the sql: SELECT field 1, field2, date_and_time, FROM table1 WHERE date_and_time =...
2
by: zaceti | last post by:
I'm new to MySQL and I am having a problem selecting the highest valued date/time for a particular day. Here is the table structure: ...
2
by: ITM | last post by:
Does anyone have an example of an SQL query which returns rows for the year-to-date, but where the "year" commences on August 1st? e.g. select * from mytable where datefield > last august 1st ...
6
by: Orson | last post by:
I have a page that uses the javascript Date() function to retrieve a date from the client computer. The date is then inserted into a note that is saved on a database. The date is in the format...
7
by: Thomi Baechler | last post by:
Hello Everybody I run the following query against to identical databases. Execution time on the first DB is 0 seconds, on the other 6 seconds! SELECT dbo.HRMABZ.EMPKEY ,...
2
by: Julie Wardlow | last post by:
Help! I am calculating a future date using the DateAdd function in a query (the calculation also involves an IIf statement), and have managed to get this formula to produce the required result....
3
by: Scotter | last post by:
Hi, I've been trying to make a report that will show the deliverys to be made between 2 dates, or the deliverys to be made after a certian date, or the deliveries that were made before a certian...
3
by: fezza1 | last post by:
Hello, I need some help, so thanks in advance. My database has 5 columns matching to particular years, i.e.,PrevYr, PrevYr1, PrevYr2, PrevYr3, PrevYr4. In a simple query, I've combined all...
0
by: Martin Ruprecht | last post by:
Hi, I do have a big problem: We are creating a reporting tool for logistic solutions using Crystal Reports. I actually am programming a history report. There are millions of lines in the...
1
by: Donna Wiley | last post by:
I have a date field that could be formatted m/d/yyyy, mm/d/yyyy, m/dd/yyyy, or mm/dd/yyyy. I need to be able to enter a start date and an end date in a parameter query, i.e. Between (date) and...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.