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

    How to search month wise data from sqlserver

    Hi Friends,

    How to search month wise data from Sql Server:

    In DB data is in the form of dd-mm-yy (ex: 05-10-1989)

    I need to get the data based on month , My problem is datatype is nvarchar(50), I can't able to get the date based on month directly.

    Thanks in Advance,

    Thanks,
    Naseer
  • #767648
    Hi,
    Use below script:

    SELECT * FROM TableName WHERE PARSENAME(REPLACE(YourInputDate, '-', '.'), 2) = '02'

    Here replace function replace '-' from db date to '/' and PARSENAME function returns the specified part of YourInputDate.

  • #767651
    Hi

    Try this



    CREATE TABLE TWW
    (
    iD INT,
    NAME VARCHAR(40),
    DATEF VARCHAR(20)
    )

    iNSERT INTO TWW VALUES(1,'aa','10-05-1989')
    iNSERT INTO TWW VALUES(1,'aa1','10-05-1989')
    iNSERT INTO TWW VALUES(1,'aa','05-05-1989')
    iNSERT INTO TWW VALUES(1,'aa','05-05-1989')

    iNSERT INTO TWW VALUES(1,'aa','08-07-1989')
    iNSERT INTO TWW VALUES(1,'aa','06-07-1989')



    SELECT ID,NAME,DATEF FROM TWW WHERE MONTH(DATEF)='06'


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments