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 SERVER 2012 - pull data from only, if value date is available

SQL SERVER 2012 - pull data from only, if value date is available

Scheduled Pinned Locked Moved Database
databasesql-serversysadminsalescollaboration
9 Posts 4 Posters 26 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.
  • J Offline
    J Offline
    joflo
    wrote on last edited by
    #1

    Hi I wish to only begin a select statement if the top value date is found - this the first of the month. It's my way of knowing data has been added into a system at the beginning of the month e.g max date is 01/11/2018. If not take the last day of the previous month 31/10/2018. Table is called sales. Column is called SaleDateFrom. I want to pull e.g data from SaleDateFrom <=01/11/2018...if not pull data SaleDateFrom <=31/10/2018 statement to change where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) Any ideas team?

    L Richard DeemingR 2 Replies Last reply
    0
    • J joflo

      Hi I wish to only begin a select statement if the top value date is found - this the first of the month. It's my way of knowing data has been added into a system at the beginning of the month e.g max date is 01/11/2018. If not take the last day of the previous month 31/10/2018. Table is called sales. Column is called SaleDateFrom. I want to pull e.g data from SaleDateFrom <=01/11/2018...if not pull data SaleDateFrom <=31/10/2018 statement to change where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) Any ideas team?

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

      This is exactly the same question as Only begin select if value is found in dataset sql - Database Discussion Boards[^] right below here. Did you create a new account just to repost this?

      J 1 Reply Last reply
      0
      • L Lost User

        This is exactly the same question as Only begin select if value is found in dataset sql - Database Discussion Boards[^] right below here. Did you create a new account just to repost this?

        J Offline
        J Offline
        joflo
        wrote on last edited by
        #3

        hi I don't know whats happened sorry...I tried so hard to edit the previous post, and it would not let me, so I signed out , went to log in it said denied, asked for reset I think it has issues if you login with facebook as uses same email. please help

        L 1 Reply Last reply
        0
        • J joflo

          hi I don't know whats happened sorry...I tried so hard to edit the previous post, and it would not let me, so I signed out , went to log in it said denied, asked for reset I think it has issues if you login with facebook as uses same email. please help

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

          If you have problems with your account then you should use the Bugs and Suggestions[^] forum to get assistance from the administrators. I suggest you do so now from your original account, and delete this one.

          1 Reply Last reply
          0
          • J joflo

            Hi I wish to only begin a select statement if the top value date is found - this the first of the month. It's my way of knowing data has been added into a system at the beginning of the month e.g max date is 01/11/2018. If not take the last day of the previous month 31/10/2018. Table is called sales. Column is called SaleDateFrom. I want to pull e.g data from SaleDateFrom <=01/11/2018...if not pull data SaleDateFrom <=31/10/2018 statement to change where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) Any ideas team?

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            Not only is this a repost of the question below, you haven't responded to any of the questions asked in response to that post. 2018-10-31 is less than 2018-11-01; therefore, if there are no records with SaleDateFrom <= '20181101', there will be no records with SaleDateFrom <= '20181031'. You need to explain what you're actually trying to achieve.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            J 1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              Not only is this a repost of the question below, you haven't responded to any of the questions asked in response to that post. 2018-10-31 is less than 2018-11-01; therefore, if there are no records with SaleDateFrom <= '20181101', there will be no records with SaleDateFrom <= '20181031'. You need to explain what you're actually trying to achieve.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              J Offline
              J Offline
              joflo
              wrote on last edited by
              #6

              I'm doing my best to explain , here is my where clause where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) I want to replace the date in bold to 20181031 if the highest date entered into the data base is not the 20181101. this is to make sure the data for the start of the month has been entered please help please see response to Richard - about account big issue, which I be contacting code project about

              Richard DeemingR J 2 Replies Last reply
              0
              • J joflo

                I'm doing my best to explain , here is my where clause where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) I want to replace the date in bold to 20181031 if the highest date entered into the data base is not the 20181101. this is to make sure the data for the start of the month has been entered please help please see response to Richard - about account big issue, which I be contacting code project about

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                And once again: If there are no records where the SaleDateFrom is on or before 1st November, then there will be no records where SaleDateFrom is on or before 31st October. If there is a record for 31st October, then that will already be included in your current query. If there are no records on or before 1st November, then changing your query to look for records with an earlier date isn't going to make any difference.


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                J 1 Reply Last reply
                0
                • Richard DeemingR Richard Deeming

                  And once again: If there are no records where the SaleDateFrom is on or before 1st November, then there will be no records where SaleDateFrom is on or before 31st October. If there is a record for 31st October, then that will already be included in your current query. If there are no records on or before 1st November, then changing your query to look for records with an earlier date isn't going to make any difference.


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  J Offline
                  J Offline
                  joflo
                  wrote on last edited by
                  #8

                  that makes sense now...fab , I totally get it. thank you team.. I do appreciate the help :-O

                  1 Reply Last reply
                  0
                  • J joflo

                    I'm doing my best to explain , here is my where clause where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) I want to replace the date in bold to 20181031 if the highest date entered into the data base is not the 20181101. this is to make sure the data for the start of the month has been entered please help please see response to Richard - about account big issue, which I be contacting code project about

                    J Offline
                    J Offline
                    James Walsh Jr
                    wrote on last edited by
                    #9

                    Why don't you use a sub-select for the date?

                    where (SaleDateFrom <= ( select max(your date column) from your table with date value ) and (SaleDateTo '20010101' or SaleDateTo is null ))

                    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