簡體   English   中英

SQL Server日期時間文字-將數據類型varchar轉換為float時出錯

[英]SQL Server datetime literal - Error converting data type varchar to float

確保我在這里缺少明顯的東西,但是如何將datetime字符串文字傳遞給SQL Server?

例如:

select * 
from [dbo].temp_rk_table 
where tx_from <= '2015-10-01T06:37:16'  
  and '2015-10-01T06:37:16' < tx_to

得到:

將數據類型varchar轉換為float時出錯。

也:

select * 
from [dbo].temp_rk_table 
where tx_from <= convert(datetime,'2015-10-01T06:37:16')
  and convert(datetime,'2015-10-01T06:37:16' ) < tx_to

得到:

GetNextRows失敗。 :將表達式轉換為數據類型datetime的算術溢出錯誤。

??

所以(根據評論)我確實缺少明顯的東西! TX_FROM和TX_TO變量定義為FLOAT,因此將不接受轉換后的日期時間字符串。

確保您的日期時間確實定義為日期時間。 下面的查詢可能有幫助( source ):

select data_type + 
    case
        when data_type like '%text' or data_type like 'image' or data_type like 'sql_variant' or data_type like 'xml'
            then ''
        when data_type = 'float'
            then '(' + convert(varchar(10), isnull(numeric_precision, 18)) + ')'
        when data_type = 'numeric' or data_type = 'decimal'
            then '(' + convert(varchar(10), isnull(numeric_precision, 18)) + ',' + convert(varchar(10), isnull(numeric_scale, 0)) + ')'
        when (data_type like '%char' or data_type like '%binary') and character_maximum_length = -1
            then '(max)'
        when character_maximum_length is not null
            then '(' + convert(varchar(10), character_maximum_length) + ')'
        else ''
    end as CONDENSED_TYPE
    , *
from information_schema.columns

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM