Solved

format function in the sql server 2000 view

Posted on 2004-08-16
5
12,409 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 125 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 125 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Join & Write a Comment

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now