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. How to get the Output based on Next Date if exists in the Table

How to get the Output based on Next Date if exists in the Table

Scheduled Pinned Locked Moved Database
tutorial
7 Posts 5 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.
  • R Offline
    R Offline
    Robymon
    wrote on last edited by
    #1

    This is my table RowNumber TestDate 1 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 3 2014-01-05 00:00:00.000 4 2014-01-06 00:00:00.000 5 2014-01-10 00:00:00.000 I want to Make Out Put Like this RowNumber StartDate EndDate 1 2014-01-01 00:00:00.000 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 2014-01-06 00:00:00.000 3 2014-01-10 00:00:00.000 2014-01-10 00:00:00.000

    L M T B 4 Replies Last reply
    0
    • R Robymon

      This is my table RowNumber TestDate 1 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 3 2014-01-05 00:00:00.000 4 2014-01-06 00:00:00.000 5 2014-01-10 00:00:00.000 I want to Make Out Put Like this RowNumber StartDate EndDate 1 2014-01-01 00:00:00.000 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 2014-01-06 00:00:00.000 3 2014-01-10 00:00:00.000 2014-01-10 00:00:00.000

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Then you really need to explain the criteria for selecting the various items. As displayed above it is not obvious how you choose which dates.

      1 Reply Last reply
      0
      • R Robymon

        This is my table RowNumber TestDate 1 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 3 2014-01-05 00:00:00.000 4 2014-01-06 00:00:00.000 5 2014-01-10 00:00:00.000 I want to Make Out Put Like this RowNumber StartDate EndDate 1 2014-01-01 00:00:00.000 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 2014-01-06 00:00:00.000 3 2014-01-10 00:00:00.000 2014-01-10 00:00:00.000

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

        Try this, changing Modified and TableName to suit.

        SELECT D.Dt, max(Modified)MaxDT,MIN(Modified)MinDT
        FROM TableName N
        INNER JOIN (SELECT DISTINCT CONVERT(DATE,Modified) Dt
        FROM TableName ) D ON D.Dt = CONVERT(DATE,N.Modified)
        GROUP BY Dt

        Never underestimate the power of human stupidity RAH

        R 1 Reply Last reply
        0
        • M Mycroft Holmes

          Try this, changing Modified and TableName to suit.

          SELECT D.Dt, max(Modified)MaxDT,MIN(Modified)MinDT
          FROM TableName N
          INNER JOIN (SELECT DISTINCT CONVERT(DATE,Modified) Dt
          FROM TableName ) D ON D.Dt = CONVERT(DATE,N.Modified)
          GROUP BY Dt

          Never underestimate the power of human stupidity RAH

          R Offline
          R Offline
          Robymon
          wrote on last edited by
          #4

          This sql not getting the correct Out put, it shows like this Dt MaxDT MinDT 2014-01-01 2014-01-01 00:00:00.000 2014-01-01 00:00:00.000 2014-01-04 2014-01-04 00:00:00.000 2014-01-04 00:00:00.000 2014-01-05 2014-01-05 00:00:00.000 2014-01-05 00:00:00.000 2014-01-06 2014-01-06 00:00:00.000 2014-01-06 00:00:00.000 2014-01-10 2014-01-10 00:00:00.000 2014-01-10 00:00:00.000 I want to get it like this way RowNumber StartDate EndDate 1 2014-01-01 00:00:00.000 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 2014-01-06 00:00:00.000 3 2014-01-10 00:00:00.000 2014-01-10 00:00:00.000

          M 1 Reply Last reply
          0
          • R Robymon

            This sql not getting the correct Out put, it shows like this Dt MaxDT MinDT 2014-01-01 2014-01-01 00:00:00.000 2014-01-01 00:00:00.000 2014-01-04 2014-01-04 00:00:00.000 2014-01-04 00:00:00.000 2014-01-05 2014-01-05 00:00:00.000 2014-01-05 00:00:00.000 2014-01-06 2014-01-06 00:00:00.000 2014-01-06 00:00:00.000 2014-01-10 2014-01-10 00:00:00.000 2014-01-10 00:00:00.000 I want to get it like this way RowNumber StartDate EndDate 1 2014-01-01 00:00:00.000 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 2014-01-06 00:00:00.000 3 2014-01-10 00:00:00.000 2014-01-10 00:00:00.000

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

            Then you are screwed, there is no indication that the 5th is not the end of a job. You have not supplied enough information.

            Never underestimate the power of human stupidity RAH

            1 Reply Last reply
            0
            • R Robymon

              This is my table RowNumber TestDate 1 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 3 2014-01-05 00:00:00.000 4 2014-01-06 00:00:00.000 5 2014-01-10 00:00:00.000 I want to Make Out Put Like this RowNumber StartDate EndDate 1 2014-01-01 00:00:00.000 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 2014-01-06 00:00:00.000 3 2014-01-10 00:00:00.000 2014-01-10 00:00:00.000

              T Offline
              T Offline
              Tim Carmichael
              wrote on last edited by
              #6

              If I understand the problem correctly, a start date means the preceeding date in not in the table; an end date is the last successive date from a start date in the table or the start date if there are no successive dates. So... 2014-01-01 is a start date because 2013-12-31 doesn't exist; 2014-01-01 is the end date because 2014-01-02 doesn't exist. 2014-01-04 is a start date because 2014-01-03 doesn't exist, giving 2014-01-06 as the end date. And so on... Given that, provide the SQL statement you are using and someone may help; don't ask them to write everything for you.

              1 Reply Last reply
              0
              • R Robymon

                This is my table RowNumber TestDate 1 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 3 2014-01-05 00:00:00.000 4 2014-01-06 00:00:00.000 5 2014-01-10 00:00:00.000 I want to Make Out Put Like this RowNumber StartDate EndDate 1 2014-01-01 00:00:00.000 2014-01-01 00:00:00.000 2 2014-01-04 00:00:00.000 2014-01-06 00:00:00.000 3 2014-01-10 00:00:00.000 2014-01-10 00:00:00.000

                B Offline
                B Offline
                Bernhard Hiller
                wrote on last edited by
                #7

                How do you expect us to find out code for that transformation if you refuse to tell us the transformation rules?

                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