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 (1) -

get more info
get more info United States
12/14/2015 6:29:22 AM #

You are a very clever person!

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5