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. Sqlserver error of date difference

Sqlserver error of date difference

Scheduled Pinned Locked Moved Database
databasehelpsysadmin
4 Posts 2 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
    snehasish
    wrote on last edited by
    #1

    hi; i want to write a sql query of different between two dates. ..................................................... DECLARE @mindays DATETIME DECLARE @today DATETIME SET @mindays =select min(daily_date) from r_dailymaterial_entry) SET @today = getdate() SELECT DATEDIFF(DAY, @mindays, @today) AS [DateDifference] ..................................................... i gets a error.. Server: Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'select'. please help me...

    W 1 Reply Last reply
    0
    • S snehasish

      hi; i want to write a sql query of different between two dates. ..................................................... DECLARE @mindays DATETIME DECLARE @today DATETIME SET @mindays =select min(daily_date) from r_dailymaterial_entry) SET @today = getdate() SELECT DATEDIFF(DAY, @mindays, @today) AS [DateDifference] ..................................................... i gets a error.. Server: Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'select'. please help me...

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      snehasish wrote:

      SET @mindays =select min(daily_date) from r_dailymaterial_entry)

      Try the following. There was an extra parenthesis in the end and when you use select, you don't use set command in the start:

      select @mindays = min(daily_date) from r_dailymaterial_entry

      The need to optimize rises from a bad design. My articles[^]

      S 1 Reply Last reply
      0
      • W Wendelius

        snehasish wrote:

        SET @mindays =select min(daily_date) from r_dailymaterial_entry)

        Try the following. There was an extra parenthesis in the end and when you use select, you don't use set command in the start:

        select @mindays = min(daily_date) from r_dailymaterial_entry

        The need to optimize rises from a bad design. My articles[^]

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

        hi Mika Wendelius, Many thanks to you for giving this solution.It works fine. Thanks once again. snehasish

        W 1 Reply Last reply
        0
        • S snehasish

          hi Mika Wendelius, Many thanks to you for giving this solution.It works fine. Thanks once again. snehasish

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          You're welcome :)

          The need to optimize rises from a bad design. My articles[^]

          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