Solved

format function in the sql server 2000 view

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Latency in .net app using DB in .net 21 63
Save conflict messages on existing documents 15 65
business objects to connect to MSSQL 6 72
Update from TABLE-A to TABLE-B 5 48
In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
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…

776 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