Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. I want to diplay particular records between two dates using nvarchar

I want to diplay particular records between two dates using nvarchar

Scheduled Pinned Locked Moved Database
helptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Samiullah
    wrote on last edited by
    #1

    Hi, I have created a table and in that i have inserted some records. then i want to display the records between specified dates then how to do that. create table rough(checkeddate nvarchar(100)) These are the inserted values.. insert into rough values('1/01/2002') insert into rough values('3/01/2002') insert into rough values('12/01/2003') insert into rough values('11/09/2006') insert into rough values('8/01/2008') insert into rough values('1/01/2004') insert into rough values('1/01/2006') insert into rough values('1/21/2003') insert into rough values('1/31/2005') insert into rough values('1/11/2006') insert into rough values('1/01/2006') insert into rough values('1/01/2002') insert into rough values('1/01/2004') insert into rough values('1/01/2006') The output as follows mm/dd/yyyy ---------- 12/01/2003 11/09/2006 1/01/2006 1/21/2003 1/31/2005 1/11/2006 1/01/2006 1/01/2006 so my requirement is now i want to diplay particular records between two dates like as follows select * from rough where checkeddate between '1/01/2006' and '12/31/2006' Can anyone help me..

    S M P 3 Replies Last reply
    0
    • S Samiullah

      Hi, I have created a table and in that i have inserted some records. then i want to display the records between specified dates then how to do that. create table rough(checkeddate nvarchar(100)) These are the inserted values.. insert into rough values('1/01/2002') insert into rough values('3/01/2002') insert into rough values('12/01/2003') insert into rough values('11/09/2006') insert into rough values('8/01/2008') insert into rough values('1/01/2004') insert into rough values('1/01/2006') insert into rough values('1/21/2003') insert into rough values('1/31/2005') insert into rough values('1/11/2006') insert into rough values('1/01/2006') insert into rough values('1/01/2002') insert into rough values('1/01/2004') insert into rough values('1/01/2006') The output as follows mm/dd/yyyy ---------- 12/01/2003 11/09/2006 1/01/2006 1/21/2003 1/31/2005 1/11/2006 1/01/2006 1/01/2006 so my requirement is now i want to diplay particular records between two dates like as follows select * from rough where checkeddate between '1/01/2006' and '12/31/2006' Can anyone help me..

      S Offline
      S Offline
      Syed Mehroz Alam
      wrote on last edited by
      #2

      Samiullah wrote:

      create table rough(checkeddate nvarchar(100))

      Why are you storing date as an nvarchar? Try using a datetime type instead and you can easily filter records using the query you mentioned. But if you still want to achieve it using an nvarchar, you can simply cast the value to a datetime. Here's a small change to your query:

      select * from rough where cast(checkeddate as datetime) between '1/01/2006' and '12/31/2006'

      Regards, Syed Mehroz Alam

      My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein

      modified on Thursday, November 13, 2008 8:22 AM

      S 1 Reply Last reply
      0
      • S Samiullah

        Hi, I have created a table and in that i have inserted some records. then i want to display the records between specified dates then how to do that. create table rough(checkeddate nvarchar(100)) These are the inserted values.. insert into rough values('1/01/2002') insert into rough values('3/01/2002') insert into rough values('12/01/2003') insert into rough values('11/09/2006') insert into rough values('8/01/2008') insert into rough values('1/01/2004') insert into rough values('1/01/2006') insert into rough values('1/21/2003') insert into rough values('1/31/2005') insert into rough values('1/11/2006') insert into rough values('1/01/2006') insert into rough values('1/01/2002') insert into rough values('1/01/2004') insert into rough values('1/01/2006') The output as follows mm/dd/yyyy ---------- 12/01/2003 11/09/2006 1/01/2006 1/21/2003 1/31/2005 1/11/2006 1/01/2006 1/01/2006 so my requirement is now i want to diplay particular records between two dates like as follows select * from rough where checkeddate between '1/01/2006' and '12/31/2006' Can anyone help me..

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        as Syed said - STORE YOUR DATES AS DATETIME. This is a fundamental error in design and you should be smacked for using nvarchar. You are now going to forever need to cast/convert that column to do anything with it. More emphasis - USE THE CORRECT DATA TYPE

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        • S Samiullah

          Hi, I have created a table and in that i have inserted some records. then i want to display the records between specified dates then how to do that. create table rough(checkeddate nvarchar(100)) These are the inserted values.. insert into rough values('1/01/2002') insert into rough values('3/01/2002') insert into rough values('12/01/2003') insert into rough values('11/09/2006') insert into rough values('8/01/2008') insert into rough values('1/01/2004') insert into rough values('1/01/2006') insert into rough values('1/21/2003') insert into rough values('1/31/2005') insert into rough values('1/11/2006') insert into rough values('1/01/2006') insert into rough values('1/01/2002') insert into rough values('1/01/2004') insert into rough values('1/01/2006') The output as follows mm/dd/yyyy ---------- 12/01/2003 11/09/2006 1/01/2006 1/21/2003 1/31/2005 1/11/2006 1/01/2006 1/01/2006 so my requirement is now i want to diplay particular records between two dates like as follows select * from rough where checkeddate between '1/01/2006' and '12/31/2006' Can anyone help me..

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Yeah, what they said... or at least use an ISO 8601 compliant format YYYY-MM-DD.

          1 Reply Last reply
          0
          • S Syed Mehroz Alam

            Samiullah wrote:

            create table rough(checkeddate nvarchar(100))

            Why are you storing date as an nvarchar? Try using a datetime type instead and you can easily filter records using the query you mentioned. But if you still want to achieve it using an nvarchar, you can simply cast the value to a datetime. Here's a small change to your query:

            select * from rough where cast(checkeddate as datetime) between '1/01/2006' and '12/31/2006'

            Regards, Syed Mehroz Alam

            My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein

            modified on Thursday, November 13, 2008 8:22 AM

            S Offline
            S Offline
            Samiullah
            wrote on last edited by
            #5

            Thanks for your immediate response. As iam new to sql server and its also my requirement to use the nvarchar thats why!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups