sql = "select scn,name,imp_flg,cg_desc from"
+" (select vesvoy.scn, vessel.name,'I' as imp_flg,cargotype.description as cg_desc from vesvoy"
+" join vessel on vesvoy.vessel_id = vessel.id "
+" join vesvoy_mf on vesvoy.id = vesvoy_mf.id_1"
+" join mf_bl on vesvoy_mf.id_2 = mf_bl.id_1"
+" join bl on mf_bl.id_2 = bl.id "
+" join blitem on blitem.master_id = bl.id"
+" join cargotype on blitem.cg_type_id = cargotype.id"
+ " where bl.inv_flg<>'1' and year(vesvoy.exp_arr_dt_tm) in year(CURRENT_TIMESTAMP) , year(CURRENT_TIMESTAMP)-1"
+" union"
+" select vesvoy.scn, vessel.name,'E' as imp_flg,cargotype.description as cg_desc"
+" from vesvoy"
+" join vessel on vesvoy.vessel_id = vessel.id "
+" join vesvoy_so on vesvoy.id = vesvoy_so.id_1"
+" join so_sso on vesvoy_so.id_2 = so_sso.id_1"
+" join sso on so_sso.id_2 = sso.id "
+" join ssoitem on ssoitem.master_id = sso.id"
+" join cargotype on ssoitem.cg_type_id = cargotype.id"
+ " where sso.inv_flg<>'1' and year(vesvoy.exp_arr_dt_tm) in year(CURRENT_TIMESTAMP) , year(CURRENT_TIMESTAMP)-1) as a ";
I did the above query.
我做了上面的查询。
Error saying that
错误说
An unexpected token "year(CURRENT_TIMESTAMP),year" was found following "oy.exp_arr_dt_tm) in . Expected tokens may include . SQLSTATE=42601"
在“oy.exp_arr_dt_tm”后面发现一个意外的令牌“year(CURRENT_TIMESTAMP),year”。预期的令牌可能包括。SQLSTATE = 42601”
2 个解决方案
#1
2
You need to define the parentheses for IN
您需要为IN定义圆括号
sql = "select scn,name,imp_flg,cg_desc from"
+" (select vesvoy.scn, vessel.name,'I' as imp_flg,cargotype.description as cg_desc from vesvoy"
+" join vessel on vesvoy.vessel_id = vessel.id "
+" join vesvoy_mf on vesvoy.id = vesvoy_mf.id_1"
+" join mf_bl on vesvoy_mf.id_2 = mf_bl.id_1"
+" join bl on mf_bl.id_2 = bl.id "
+" join blitem on blitem.master_id = bl.id"
+" join cargotype on blitem.cg_type_id = cargotype.id"
+ " where bl.inv_flg<>'1' and year(vesvoy.exp_arr_dt_tm) in (year(CURRENT_TIMESTAMP) , year(CURRENT_TIMESTAMP)-1)"
+" union"
+" select vesvoy.scn, vessel.name,'E' as imp_flg,cargotype.description as cg_desc"
+" from vesvoy"
+" join vessel on vesvoy.vessel_id = vessel.id "
+" join vesvoy_so on vesvoy.id = vesvoy_so.id_1"
+" join so_sso on vesvoy_so.id_2 = so_sso.id_1"
+" join sso on so_sso.id_2 = sso.id "
+" join ssoitem on ssoitem.master_id = sso.id"
+" join cargotype on ssoitem.cg_type_id = cargotype.id"
+ " where sso.inv_flg<>'1' and year(vesvoy.exp_arr_dt_tm) in (year(CURRENT_TIMESTAMP) , year(CURRENT_TIMESTAMP)-1) as a"
#2
2
In SQL Server, the current datetime is called by GetDate(). Also, when using IN, the list needs to be enclosed in parentheses so it would look like
在SQL Server中,GetDate()调用当前的datetime。此外,在使用IN时,列表需要用圆括号括起来,以便看起来像这样
and year(vesvoy.exp_arr_dt_tm) in (year(GETDATE()) , year(GETDATE())-1)
#1
2
You need to define the parentheses for IN
您需要为IN定义圆括号
sql = "select scn,name,imp_flg,cg_desc from"
+" (select vesvoy.scn, vessel.name,'I' as imp_flg,cargotype.description as cg_desc from vesvoy"
+" join vessel on vesvoy.vessel_id = vessel.id "
+" join vesvoy_mf on vesvoy.id = vesvoy_mf.id_1"
+" join mf_bl on vesvoy_mf.id_2 = mf_bl.id_1"
+" join bl on mf_bl.id_2 = bl.id "
+" join blitem on blitem.master_id = bl.id"
+" join cargotype on blitem.cg_type_id = cargotype.id"
+ " where bl.inv_flg<>'1' and year(vesvoy.exp_arr_dt_tm) in (year(CURRENT_TIMESTAMP) , year(CURRENT_TIMESTAMP)-1)"
+" union"
+" select vesvoy.scn, vessel.name,'E' as imp_flg,cargotype.description as cg_desc"
+" from vesvoy"
+" join vessel on vesvoy.vessel_id = vessel.id "
+" join vesvoy_so on vesvoy.id = vesvoy_so.id_1"
+" join so_sso on vesvoy_so.id_2 = so_sso.id_1"
+" join sso on so_sso.id_2 = sso.id "
+" join ssoitem on ssoitem.master_id = sso.id"
+" join cargotype on ssoitem.cg_type_id = cargotype.id"
+ " where sso.inv_flg<>'1' and year(vesvoy.exp_arr_dt_tm) in (year(CURRENT_TIMESTAMP) , year(CURRENT_TIMESTAMP)-1) as a"
#2
2
In SQL Server, the current datetime is called by GetDate(). Also, when using IN, the list needs to be enclosed in parentheses so it would look like
在SQL Server中,GetDate()调用当前的datetime。此外,在使用IN时,列表需要用圆括号括起来,以便看起来像这样
and year(vesvoy.exp_arr_dt_tm) in (year(GETDATE()) , year(GETDATE())-1)