无法从字符串转换日期和/或时间
我在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有引用 datetime 和 string 文字。由于不需要而删除转换为DateTime。 汇总是一个保留的词,它可能有效,但可以在括号中肯定。
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.