无法从字符串转换日期和/或时间

发布于 2025-02-09 07:04:47 字数 3216 浏览 1 评论 0原文

我在Laravel的Tinker中执行查询时遇到了问题,在Datagrip中它可以工作,而在修补匠中则没有。遵循上述查询:

Illuminate\Database\QueryException with message 'SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Falha ao converter data e/ou hora da cadeia de caracteres. (SQL: select count(*) as aggregate from [View_Boleto_Prop_Condominio] where [Unidade_lan] = 1 and [Id_Condo_lan] = 77 and [Data_pagamento] is null and [Bol_vencimento] > (convert(datetime, 2022-06-21)) and ([Especifica_boleto] like %ACORDO JUDICIAL% or [Especifica_boleto] like %ACORDO EXTRAJUDICIAL%))'
>>> BoletoPropCondominio::where('Unidade_lan', 0001)->where('Id_Condo_lan', 77)->whereNull('Data_pagamento')->where('Bol_vencimento', '>', "(convert(datetime, ".$bol_vencimento.", 121))")->where(function($query) { $query->where('Especifica_boleto', 'like', '%ACORDO JUDICIAL%')->orWhere('Especifica_boleto', 'like', '%ACORDO EXTRAJUDICIAL%');})->count();
Illuminate\Database\QueryException with message 'SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Falha ao converter data e/ou hora da cadeia de caracteres. (SQL: select count(*) as aggregate from [View_Boleto_Prop_Condominio] where [Unidade_lan] = 1 and [Id_Condo_lan] = 77 and [Data_pagamento] is null and [Bol_vencimento] > (convert(datetime, 2022-06-21, 121)) and ([Especifica_boleto] like %ACORDO JUDICIAL% or [Especifica_boleto] like %ACORDO EXTRAJUDICIAL%))'
>>> BoletoPropCondominio::where('Unidade_lan', 0001)->where('Id_Condo_lan', 77)->whereNull('Data_pagamento')->where('Bol_vencimento', '>', "(convert(datetime, ".$bol_vencimento.", 102))")->where(function($query) { $query->where('Especifica_boleto', 'like', '%ACORDO JUDICIAL%')->orWhere('Especifica_boleto', 'like', '%ACORDO EXTRAJUDICIAL%');})->count();
Illuminate\Database\QueryException with message 'SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Falha ao converter data e/ou hora da cadeia de caracteres. (SQL: select count(*) as aggregate from [View_Boleto_Prop_Condominio] where [Unidade_lan] = 1 and [Id_Condo_lan] = 77 and [Data_pagamento] is null and [Bol_vencimento] > (convert(datetime, 2022-06-21, 102)) and ([Especifica_boleto] like %ACORDO JUDICIAL% or [Especifica_boleto] like %ACORDO EXTRAJUDICIAL%))'
>>> BoletoPropCondominio::where('Unidade_lan', 0001)->where('Id_Condo_lan', 77)->whereNull('Data_pagamento')->where('Bol_vencimento', '>', "(convert(datetime, ".$bol_vencimento.", 105))")->where(function($query) { $query->where('Especifica_boleto', 'like', '%ACORDO JUDICIAL%')->orWhere('Especifica_boleto', 'like', '%ACORDO EXTRAJUDICIAL%');})->count();
Illuminate\Database\QueryException with message 'SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Falha ao converter data e/ou hora da cadeia de caracteres. (SQL: select count(*) as aggregate from [View_Boleto_Prop_Condominio] where [Unidade_lan] = 1 and [Id_Condo_lan] = 77 and [Data_pagamento] is null and [Bol_vencimento] > (convert(datetime, 2022-06-21, 105)) and ([Especifica_boleto] like %ACORDO JUDICIAL% or [Especifica_boleto] like %ACORDO EXTRAJUDICIAL%))'

I'm having problems executing a query in Laravel's Tinker, where in DataGrip it works and in Tinker it doesn't. Follow the above queries:

Illuminate\Database\QueryException with message 'SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Falha ao converter data e/ou hora da cadeia de caracteres. (SQL: select count(*) as aggregate from [View_Boleto_Prop_Condominio] where [Unidade_lan] = 1 and [Id_Condo_lan] = 77 and [Data_pagamento] is null and [Bol_vencimento] > (convert(datetime, 2022-06-21)) and ([Especifica_boleto] like %ACORDO JUDICIAL% or [Especifica_boleto] like %ACORDO EXTRAJUDICIAL%))'
>>> BoletoPropCondominio::where('Unidade_lan', 0001)->where('Id_Condo_lan', 77)->whereNull('Data_pagamento')->where('Bol_vencimento', '>', "(convert(datetime, ".$bol_vencimento.", 121))")->where(function($query) { $query->where('Especifica_boleto', 'like', '%ACORDO JUDICIAL%')->orWhere('Especifica_boleto', 'like', '%ACORDO EXTRAJUDICIAL%');})->count();
Illuminate\Database\QueryException with message 'SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Falha ao converter data e/ou hora da cadeia de caracteres. (SQL: select count(*) as aggregate from [View_Boleto_Prop_Condominio] where [Unidade_lan] = 1 and [Id_Condo_lan] = 77 and [Data_pagamento] is null and [Bol_vencimento] > (convert(datetime, 2022-06-21, 121)) and ([Especifica_boleto] like %ACORDO JUDICIAL% or [Especifica_boleto] like %ACORDO EXTRAJUDICIAL%))'
>>> BoletoPropCondominio::where('Unidade_lan', 0001)->where('Id_Condo_lan', 77)->whereNull('Data_pagamento')->where('Bol_vencimento', '>', "(convert(datetime, ".$bol_vencimento.", 102))")->where(function($query) { $query->where('Especifica_boleto', 'like', '%ACORDO JUDICIAL%')->orWhere('Especifica_boleto', 'like', '%ACORDO EXTRAJUDICIAL%');})->count();
Illuminate\Database\QueryException with message 'SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Falha ao converter data e/ou hora da cadeia de caracteres. (SQL: select count(*) as aggregate from [View_Boleto_Prop_Condominio] where [Unidade_lan] = 1 and [Id_Condo_lan] = 77 and [Data_pagamento] is null and [Bol_vencimento] > (convert(datetime, 2022-06-21, 102)) and ([Especifica_boleto] like %ACORDO JUDICIAL% or [Especifica_boleto] like %ACORDO EXTRAJUDICIAL%))'
>>> BoletoPropCondominio::where('Unidade_lan', 0001)->where('Id_Condo_lan', 77)->whereNull('Data_pagamento')->where('Bol_vencimento', '>', "(convert(datetime, ".$bol_vencimento.", 105))")->where(function($query) { $query->where('Especifica_boleto', 'like', '%ACORDO JUDICIAL%')->orWhere('Especifica_boleto', 'like', '%ACORDO EXTRAJUDICIAL%');})->count();
Illuminate\Database\QueryException with message 'SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Falha ao converter data e/ou hora da cadeia de caracteres. (SQL: select count(*) as aggregate from [View_Boleto_Prop_Condominio] where [Unidade_lan] = 1 and [Id_Condo_lan] = 77 and [Data_pagamento] is null and [Bol_vencimento] > (convert(datetime, 2022-06-21, 105)) and ([Especifica_boleto] like %ACORDO JUDICIAL% or [Especifica_boleto] like %ACORDO EXTRAJUDICIAL%))'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶气 2025-02-16 07:04:48

您没有引用 datetime string 文字。由于不需要而删除转换为DateTime。 汇总是一个保留的词,它可能有效,但可以在括号中肯定。

select count(*) [aggregate] 
from [View_Boleto_Prop_Condominio] 
where [Unidade_lan] = 1 
and [Id_Condo_lan] = 77 
and [Data_pagamento] is null 
and [Bol_vencimento] > '2022-06-21' 
and ([Especifica_boleto] like '%ACORDO JUDICIAL%' or [Especifica_boleto] like '%ACORDO EXTRAJUDICIAL%')

You are not quoting the datetime and your string literals. Removed the convert to datetime as it is not needed. Also aggregate is a reserved word, it might work but put it in brackets to be sure.

select count(*) [aggregate] 
from [View_Boleto_Prop_Condominio] 
where [Unidade_lan] = 1 
and [Id_Condo_lan] = 77 
and [Data_pagamento] is null 
and [Bol_vencimento] > '2022-06-21' 
and ([Especifica_boleto] like '%ACORDO JUDICIAL%' or [Especifica_boleto] like '%ACORDO EXTRAJUDICIAL%')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文