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. SQL Query

SQL Query

Scheduled Pinned Locked Moved Database
csharpdatabasesql-servertutorial
4 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
    suketh
    wrote on last edited by
    #1

    Hi, please can anyone let me know the date formats in sql server for this query. my table structure is" PDate PMonth PYear 10 05 2007 03 05 2004 12 10 2007 o1 12 2005 now i have to retrieve the records based on some specified dates. for example, i want the records which matches "12/10/2007" i know how to write the code for these 3 columns to format (mm/dd/yyyy)using C# & vb.Net but i want to know how to write using Tsql Thanks, Suketh

    H S R 3 Replies Last reply
    0
    • S suketh

      Hi, please can anyone let me know the date formats in sql server for this query. my table structure is" PDate PMonth PYear 10 05 2007 03 05 2004 12 10 2007 o1 12 2005 now i have to retrieve the records based on some specified dates. for example, i want the records which matches "12/10/2007" i know how to write the code for these 3 columns to format (mm/dd/yyyy)using C# & vb.Net but i want to know how to write using Tsql Thanks, Suketh

      H Offline
      H Offline
      Harini N K
      wrote on last edited by
      #2

      Hi Use the date functions like Month(), Day() and Year() to get month,date and year. Based on these functions you can filter records. For example Month(DateColumn) will display month of the given datecolumn Hope you got it... :)

      Harini

      1 Reply Last reply
      0
      • S suketh

        Hi, please can anyone let me know the date formats in sql server for this query. my table structure is" PDate PMonth PYear 10 05 2007 03 05 2004 12 10 2007 o1 12 2005 now i have to retrieve the records based on some specified dates. for example, i want the records which matches "12/10/2007" i know how to write the code for these 3 columns to format (mm/dd/yyyy)using C# & vb.Net but i want to know how to write using Tsql Thanks, Suketh

        S Offline
        S Offline
        shally_79
        wrote on last edited by
        #3

        use this query select * from t1 where pdate=day('10/12/2007') and pmonth=month('10/12/2007') and pyear=year('10/12/2007') Note= you should format the date as 'MM/dd/yyyy' date function returns day('10/12/2007') as 12

        shally

        1 Reply Last reply
        0
        • S suketh

          Hi, please can anyone let me know the date formats in sql server for this query. my table structure is" PDate PMonth PYear 10 05 2007 03 05 2004 12 10 2007 o1 12 2005 now i have to retrieve the records based on some specified dates. for example, i want the records which matches "12/10/2007" i know how to write the code for these 3 columns to format (mm/dd/yyyy)using C# & vb.Net but i want to know how to write using Tsql Thanks, Suketh

          R Offline
          R Offline
          raj code
          wrote on last edited by
          #4

          set dateformat dmy Go select * from Table where Pdate=select Datepart(Day,'12/10/2007') and PMonth=Datepart(Month,'12/10/2007') and PYear=Datepart(Year,'12/10/2007')

          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