Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

format function in the sql server 2000 view

Posted on 2004-08-16
5
Medium Priority
?
12,430 Views
Last Modified: 2011-08-18
I am using Ms Access database, I have a query which gets the month and year of the date. to do so I use
Format([Date],"mm") AS [Month], Format([Date],"yyyy") AS [Year]
where date is the date in the table. Now I want to do the same in Sql server 2000 view where it does not accept the format function in the sql view.
please help me and solve my problem

thanks
0
Comment
Question by:ShakeelAhmed
  • 2
5 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 11810126
Select Month([Date]) as [Month], Year([Date]) as [Year] from MyTable

AW

0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 500 total points
ID: 11810167
SQL Server has Built-in functions to retrieve the Month and Year (and Day for that matter)value( as Numbers) of a Date field, though it is NOT a good idea to name fields (even as Aliases) as Year, Month, Day or Date - all of which are generally reserved words.

AW
0
 
LVL 9

Assisted Solution

by:paelo
paelo earned 500 total points
ID: 11810321
You can also use T-SQL's CONVERT function to convert a datetime field to several different predefined formats.  The below MSDN link documents many of these formats:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp

-Paul.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

963 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