aspx Tutorial

NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services,
Advertise Here

Toolbar

Get our toolbar!

Advertize



Posted by Aamir Hasan   on Sunday, March 27, 2011 Total Views:  

In this example, you will see how to get month name from input data. I have used build in function named DATETIME. DATETIME function used two parameters. DATETIME function will always return a string. I have created a virtual table and inserted some dummy records to display it.

Syntax

DATENAME ( datepart , date )

Example

DECLARE @PATIENT TABLE

    (

      ID BIGINT IDENTITY ,

      FULLNAME VARCHAR(50) ,

      GENDER CHAR ,

      BIRTHDAY DATE

    )

INSERT  INTO @PATIENT

VALUES  ( 'AAMIR HASAN', 'M', '2000-11-11' ),

        ( 'AWAIS AHMED', 'M', '2006-10-01' ),

        ( 'HINA KHAN', 'F', '2005-12-02' ),

        ( 'SABA KHAN', 'F', '2004-09-04' ),

        ( 'DIVAN', 'M', '2003-03-08' ),

        ( 'AAMIR', 'M', '2002-01-11' )

SELECT  ID ,

        FULLNAME ,

        GENDER = CASE GENDER

                   WHEN 'M' THEN 'MALE'

                   WHEN 'F' THEN 'FEMALE'

                 END ,

        [BORTHDAY MONTH NAME] = UPPER(DATENAME(MONTH, BIRTHDAY))

FROM    @PATIENT

Output

Download

How to get Month Name in T-SQL.sql (682.00 bytes)

Protected by Copyscape Online Plagiarism Tool

Comments (4) -

Chinese Restaurant Supplies
Chinese Restaurant Supplies United States
10/15/2013 9:28:54 PM #

Hi there, simply become aware of your blog through Google, and found that it's truly informative. I'm gonna be careful for brussels. I will appreciate should you continue this in future. Lots of people will be benefited out of your writing. Cheers!|

Josefa Rodabaugh
Josefa Rodabaugh United States
6/3/2014 7:09:31 AM #

You should take part in a contest for one of the best blogs on the web. I will recommend this site! More For xxx video http://www.uxxx.me/

Andres Rupar
Andres Rupar United States
9/18/2014 8:28:32 AM #

I usually learn something when i stop by here, Eric. Thanks!

Lupe Nickel
Lupe Nickel United States
9/27/2014 9:19:08 AM #

Great post. I was checking continuously this blog and I�m impressed! Extremely useful info specially the last part

Erwin Lundholm
Erwin Lundholm United States
9/27/2014 10:29:11 PM #

wow there is some very cool gadgets in here

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5