Solved

format function in the sql server 2000 view

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
free version of MSSQL for over 10GB DB 19 69
SQL Query assistance 16 36
Comparison query - 4 columns 9 26
Display SQL 2008 last modified/update Database 11 19
This article describes some very basic things about SQL Server filegroups.
Creating and Managing Databases with phpMyAdmin in cPanel.
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…

831 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