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. Query + Variable problem

Query + Variable problem

Scheduled Pinned Locked Moved Database
databasehelpmysqlsql-serversysadmin
6 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.
  • A Offline
    A Offline
    archangel717
    wrote on last edited by
    #1

    Hey all, I have a need to create a retention report in mysql/sql server that I can use to find out how many customers have canceled within 30,60,90 days of their sale date. So my query is something like this in mysql: SELECT t1.sale_date, t1.primary_phone, t1.cancel_date FROM n.orders as t1 where t1.sale_date between "2007-08-01" and "2007-08-31" order by t1.date_entered I need to be able to say something like and t1.cancel_date <= 30 days + sale_date. Does this make sense? I'm not sure how to do this without adding a more complex script, but you guys are the experts! Please help! Thanks

    A D 2 Replies Last reply
    0
    • A archangel717

      Hey all, I have a need to create a retention report in mysql/sql server that I can use to find out how many customers have canceled within 30,60,90 days of their sale date. So my query is something like this in mysql: SELECT t1.sale_date, t1.primary_phone, t1.cancel_date FROM n.orders as t1 where t1.sale_date between "2007-08-01" and "2007-08-31" order by t1.date_entered I need to be able to say something like and t1.cancel_date <= 30 days + sale_date. Does this make sense? I'm not sure how to do this without adding a more complex script, but you guys are the experts! Please help! Thanks

      A Offline
      A Offline
      andyharman
      wrote on last edited by
      #2

      In SQL-Server you would use the DateAdd function to add 30 days.

      1 Reply Last reply
      0
      • A archangel717

        Hey all, I have a need to create a retention report in mysql/sql server that I can use to find out how many customers have canceled within 30,60,90 days of their sale date. So my query is something like this in mysql: SELECT t1.sale_date, t1.primary_phone, t1.cancel_date FROM n.orders as t1 where t1.sale_date between "2007-08-01" and "2007-08-31" order by t1.date_entered I need to be able to say something like and t1.cancel_date <= 30 days + sale_date. Does this make sense? I'm not sure how to do this without adding a more complex script, but you guys are the experts! Please help! Thanks

        D Offline
        D Offline
        DoomedOne
        wrote on last edited by
        #3

        Use the dateadd function where t1.cancel_date <= dateadd("d", 30, sale_date) Hope it helps

        Habetis bona deum

        A 1 Reply Last reply
        0
        • D DoomedOne

          Use the dateadd function where t1.cancel_date <= dateadd("d", 30, sale_date) Hope it helps

          Habetis bona deum

          A Offline
          A Offline
          archangel717
          wrote on last edited by
          #4

          Thanks guys! I still have a problem with my formatting somewhere because in mysql I get the error "no database is selected". I played around with the query and got another error saying that "n.dateadd does not exist". It seems like I need some parenthesis or something. Does anyone know the specifics of how to use this function right in mysql? I've searched around, and I've had problem fitting it to my situation. Thanks all!

          A 1 Reply Last reply
          0
          • A archangel717

            Thanks guys! I still have a problem with my formatting somewhere because in mysql I get the error "no database is selected". I played around with the query and got another error saying that "n.dateadd does not exist". It seems like I need some parenthesis or something. Does anyone know the specifics of how to use this function right in mysql? I've searched around, and I've had problem fitting it to my situation. Thanks all!

            A Offline
            A Offline
            archangel717
            wrote on last edited by
            #5

            Ok so dateadd in mysql is just date_add! Doh! My syntax is still off though because I'm getting 1064 errors. I've got: SELECT * FROM orders where date_entered between "2007-08-01" and "2007-08-31" and cxldate <> "0" and cxldate <= date_add('day', 30, date_entered) cxldate stands for cancel date I get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '30, date_entered)' at line 2

            P 1 Reply Last reply
            0
            • A archangel717

              Ok so dateadd in mysql is just date_add! Doh! My syntax is still off though because I'm getting 1064 errors. I've got: SELECT * FROM orders where date_entered between "2007-08-01" and "2007-08-31" and cxldate <> "0" and cxldate <= date_add('day', 30, date_entered) cxldate stands for cancel date I get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '30, date_entered)' at line 2

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Try here[^] for some more information.

              Deja View - the feeling that you've seen this post before.

              My blog | 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