You must Sign In to post a response.
  • Category: SQL Server

    How to fetch gender from database ?


    Are you looking for a way to fetch gender from database ? then read this thread to know how to fetch it



    Gender Male Saved as M and Female as F in Database, need query to display M as Male and F as Female
  • #744801
    Hi,

    Try using this,

    SELECT
    case when Gender= 'M' then 'Male' Else
    'Female' end
    FROM [DBName].[dbo].[TableName]

    Thanks,
    Ashwini

  • #744805
    Hai Rajanikanth,
    You can use the Case statement in sql server to select the Male if the value is 'M' and Female if the value is 'F' as below:

    SELECT
    case when Gender= 'M' then 'Male'
    case when Gender= 'F' then 'Female'
    Else ''
    End
    FROM <TableName>

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #744820
    You can use SELECT ... CASE in database, just check the case if it is M then return MALE and if it F then return FEMALE
    see below snippet

    SELECT EMPName,
    CASE EmpGender
    WHEN 'M' THEN 'Male'
    WHEN 'F' THEN 'Female'
    ELSE 'Gender not found in database'
    END

    FROM EMP
    where EMPId = 10

    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #744821
    Hi,

    You can use the following Query for fetching the Male and Female

    Select *,Gender = case when Gender='M' then 'Male' when 'F' then 'Female' end
    from Tablename

  • #744835
    Try below code and see if it gives the result you are looking for.


    select CASE WHEN Gender = 'M' THEN 'Male' Else 'Female' END AS [Gender] from tblName


    Regards,
    Asheej T K

  • #744882
    supper..works well.. thanks a lot sir

  • #744983
    Hi,

    Use case statement to display "M" as Male and "F" as Female.

    EX:

    select case when Gender='M' then 'Male' Else 'Female' End from tablename

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments