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. Disallowed implicit conversion from data type smalldatetime to data type float

Disallowed implicit conversion from data type smalldatetime to data type float

Scheduled Pinned Locked Moved Database
helpdatabasecsharpphpsql-server
6 Posts 3 Posters 3 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
    jkirkerx
    wrote on last edited by
    #1

    I took a PHP job, upgrading an old PHP 4.7 project to PHP 7.14. I'm doing pretty good rewriting it as an object oriented app, and re imagining the design. But I'm terrible at SQL, and glad Linq came along. I get the error message below, and played around with the statement, ruling out that the cast is the issue. I think the date I put in bold is the issue, because I removed the line and it ran fine. I get the convert part, but should I convert to a float as well? Why a float if so? Is the date really stored as numbers?

    Error Message:
    Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 260 [code] => 260 [2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Disallowed implicit conversion from data type smalldatetime to data type float, table 'commission_summary', column 'startup_check_date'. Use the CONVERT function to run this query. [message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Disallowed implicit conversion from data type smalldatetime to data type float, table 'commission_summary', column 'startup_check_date'. Use the CONVERT function to run this query. ) )

    getSalesBonusByDate 362: SELECT count (a.project_no) FROM project as a, commission_summary as b WHERE a.project_no = b.project_no AND (a.sold_date <= 3-1-2021) AND (a.status = 'construction' or a.status = 'finished') AND ((CAST(FLOOR(b.startup_check_date)AS DATETIME) BETWEEN 1-1-2021 AND 3-1-2021)) AND a.sales_no = '79' 1

    Query: I think the date in bold is the error, but I'm not sure what to convert the value to. The field is a smalldatetime.

    SELECT count (a.project_no) FROM project as a, commission_summary as b WHERE a.project_no = b.project_no AND (a.sold_date <= 3-1-2021) AND (a.status = 'construction' or a.status = 'finished') AND ((CAST(FLOOR(b.startup_check_date)AS DATETIME) BETWEEN 1-1-2021 AND 3-1-2021)) AND a.sales_no = '79'

    If it ain't broke don't fix it Discover my world at jkirkerx.com

    V 1 Reply Last reply
    0
    • J jkirkerx

      I took a PHP job, upgrading an old PHP 4.7 project to PHP 7.14. I'm doing pretty good rewriting it as an object oriented app, and re imagining the design. But I'm terrible at SQL, and glad Linq came along. I get the error message below, and played around with the statement, ruling out that the cast is the issue. I think the date I put in bold is the issue, because I removed the line and it ran fine. I get the convert part, but should I convert to a float as well? Why a float if so? Is the date really stored as numbers?

      Error Message:
      Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 260 [code] => 260 [2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Disallowed implicit conversion from data type smalldatetime to data type float, table 'commission_summary', column 'startup_check_date'. Use the CONVERT function to run this query. [message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Disallowed implicit conversion from data type smalldatetime to data type float, table 'commission_summary', column 'startup_check_date'. Use the CONVERT function to run this query. ) )

      getSalesBonusByDate 362: SELECT count (a.project_no) FROM project as a, commission_summary as b WHERE a.project_no = b.project_no AND (a.sold_date <= 3-1-2021) AND (a.status = 'construction' or a.status = 'finished') AND ((CAST(FLOOR(b.startup_check_date)AS DATETIME) BETWEEN 1-1-2021 AND 3-1-2021)) AND a.sales_no = '79' 1

      Query: I think the date in bold is the error, but I'm not sure what to convert the value to. The field is a smalldatetime.

      SELECT count (a.project_no) FROM project as a, commission_summary as b WHERE a.project_no = b.project_no AND (a.sold_date <= 3-1-2021) AND (a.status = 'construction' or a.status = 'finished') AND ((CAST(FLOOR(b.startup_check_date)AS DATETIME) BETWEEN 1-1-2021 AND 3-1-2021)) AND a.sales_no = '79'

      If it ain't broke don't fix it Discover my world at jkirkerx.com

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      try '3-1-2021' rather than 3-1-2021

      J J 2 Replies Last reply
      0
      • V Victor Nijegorodov

        try '3-1-2021' rather than 3-1-2021

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

        Good idea and tried it, but I think I need to study convert and learn it really fast.

        If it ain't broke don't fix it Discover my world at jkirkerx.com

        1 Reply Last reply
        0
        • V Victor Nijegorodov

          try '3-1-2021' rather than 3-1-2021

          J Offline
          J Offline
          jsc42
          wrote on last edited by
          #4

          SQL Server uses ISO dates, so it should be '2021-03-01' (if you are wanting 1st March) or '2021-01-03' (for 3rd January) - the quotes are needed

          J 1 Reply Last reply
          0
          • J jsc42

            SQL Server uses ISO dates, so it should be '2021-03-01' (if you are wanting 1st March) or '2021-01-03' (for 3rd January) - the quotes are needed

            J Offline
            J Offline
            jkirkerx
            wrote on last edited by
            #5

            Ok ... The dates stored in the database are like 3/1/2021 as smalldatetime But I'm asking to compare against 2021-03-01, an ISO date, so wrap what I'm asking to compare to. I came up with this ...

            $query = "
            SELECT
            count (a.project_no)
            FROM project as a, commission_summary as b
            WHERE a.project_no = b.project_no
            AND (a.sold_date <= '$lastDate')
            AND (a.status = 'construction' or a.status = 'finished')
            AND (convert(CHAR(10), b.startup_check_date, 120) BETWEEN '$firstDate' AND '$lastDate')
            AND a.sales_no = '$salesId'";

            I fiddled with the conversion, and was sure I got it right but it failed. Then I used the suggestion to wrap the dates in single quotes and it produced a clean result of 9. I get the convert part, declare a CHAR no more than 10, input value, ? Not sure what the 120 stands for. However your explanation of the date formats has schooled me in how to fiddle with them and get it right. Just FYI, I wrote some other fixes earlier that are similar, and just had a complete blackout of my previous experiences. But this lesson should solidify it. Thanks!

            If it ain't broke don't fix it Discover my world at jkirkerx.com

            J 1 Reply Last reply
            0
            • J jkirkerx

              Ok ... The dates stored in the database are like 3/1/2021 as smalldatetime But I'm asking to compare against 2021-03-01, an ISO date, so wrap what I'm asking to compare to. I came up with this ...

              $query = "
              SELECT
              count (a.project_no)
              FROM project as a, commission_summary as b
              WHERE a.project_no = b.project_no
              AND (a.sold_date <= '$lastDate')
              AND (a.status = 'construction' or a.status = 'finished')
              AND (convert(CHAR(10), b.startup_check_date, 120) BETWEEN '$firstDate' AND '$lastDate')
              AND a.sales_no = '$salesId'";

              I fiddled with the conversion, and was sure I got it right but it failed. Then I used the suggestion to wrap the dates in single quotes and it produced a clean result of 9. I get the convert part, declare a CHAR no more than 10, input value, ? Not sure what the 120 stands for. However your explanation of the date formats has schooled me in how to fiddle with them and get it right. Just FYI, I wrote some other fixes earlier that are similar, and just had a complete blackout of my previous experiences. But this lesson should solidify it. Thanks!

              If it ain't broke don't fix it Discover my world at jkirkerx.com

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

              I am not sure why you are converting to CHAR(10) when you are looking for a date comparison/ What you are converting is your b.startup_chack_date value. If that is already a date then it does not need converting. For the meaning of the 120 (and other values) see, for example, <a href="https://www.w3schools.com/SQL/func_sqlserver_convert.asp">[^]

              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