运行时错误';13';:SQL代码中的类型不匹配
我在VBA中的部分SQL代码存在“运行时错误”13:类型不匹配 错误所指的代码是:运行时错误';13';:SQL代码中的类型不匹配,sql,vba,Sql,Vba,我在VBA中的部分SQL代码存在“运行时错误”13:类型不匹配 错误所指的代码是: SQL = SQL & " (select unique sv.gps_planshpdate from oes_delsegview sv, oes_opos op, oes_oposdelseg ds, oes_nrbom nb, ncf_comppart cp where cp.item_part_no = pd.part_no and nb.c_catnr = cp.catnr and nb.
SQL = SQL & " (select unique sv.gps_planshpdate from oes_delsegview sv, oes_opos op, oes_oposdelseg ds, oes_nrbom nb, ncf_comppart cp where cp.item_part_no = pd.part_no and nb.c_catnr = cp.catnr and nb.c_prodtyp = cp.prodtyp and nb.c_packtyp = cp.packtyp and nb.c_vernr = cp.vernr " & _
SQL = SQL & " and sv.ordnr = ds.ordnr and sv.posnr = ds.posnr and sv.catnr = nb.p_catnr and sv.prodtyp = nb.p_prodtyp and sv.packtyp = nb.p_packtyp and op.ordnr = ds.ordnr and op.posnr = ds.posnr and op.catnr = nb.p_catnr and op.prodtyp = nb.p_prodtyp and op.packtyp = nb.p_packtyp " & _
SQL = SQL & " and op.vernr = nb.p_vernr and nb.active = 'Y' and op.ol_typ in ('XX','CO') and sv.gps_planshpdate = " & _
SQL = SQL & " (select max(sv1.gps_planshpdate) from oes_delsegview sv1, oes_opos op1, oes_oposdelseg ds1, oes_nrbom nb1, ncf_comppart cp1 where cp1.item_part_no = cp.item_part_no and nb1.c_catnr = cp1.catnr " & _
SQL = SQL & " and nb1.c_prodtyp = cp1.prodtyp and nb1.c_packtyp = cp1.packtyp and nb1.c_vernr = cp1.vernr and sv1.ordnr = ds1.ordnr and sv1.posnr = ds1.posnr and sv1.catnr = nb1.p_catnr and sv1.prodtyp = nb1.p_prodtyp and sv1.packtyp = nb1.p_packtyp " & _
SQL = SQL & " and op1.ordnr = ds1.ordnr and op1.posnr = ds1.posnr and op1.catnr = nb1.p_catnr and op1.prodtyp = nb1.p_prodtyp and op1.packtyp = nb1.p_packtyp and op1.vernr = nb1.p_vernr and nb1.active = 'Y' and sv1.ord_o_status = '9' and op1.ol_typ in ('XX','CO'))), " 'last_ship_date_manufacturing
你知道如何在没有“类型不匹配”错误的情况下运行这段代码吗
谢谢当我计算表达式时,它返回
FALSE
,这肯定是导致不匹配错误的原因,因为SQL需要字符串查询
问题在于您原来的连接方法,它错误地组合了两件事
如果您想这样做:
Sql = Sql & " some expression"
Sql = Sql & " some other expression"
'Etc.
注意,在上面的例子中,我没有像你一样继续这一行:
Sql = Sql & " some expression" & _
Sql = Sql & " some other expression"
这将引起一个错误。因此,想象一下:
Sql = Sql & " A " & Sql = Sql & " B "
或:
由于此表达式的逻辑计算结果为False
:此赋值语句的右侧是一个等价语句,并且由于等价语句中的两个表达式不相等,因此只能返回False
我没有对您的查询表达式进行任何更改,只是纠正了对行连续字符的误用:
Dim SQL As String
SQL = SQL & " (select unique sv.gps_planshpdate from oes_delsegview sv, " & _
"oes_opos op, oes_oposdelseg ds, oes_nrbom nb, ncf_comppart cp " & _
"where cp.item_part_no = pd.part_no and nb.c_catnr = cp.catnr and " & _
"nb.c_prodtyp = cp.prodtyp and nb.c_packtyp = cp.packtyp and nb.c_vernr = cp.vernr " & _
" and sv.ordnr = ds.ordnr and sv.posnr = ds.posnr and sv.catnr = nb.p_catnr " & _
"and sv.prodtyp = nb.p_prodtyp and sv.packtyp = nb.p_packtyp and op.ordnr = ds.ordnr " & _
"and op.posnr = ds.posnr and op.catnr = nb.p_catnr and op.prodtyp = nb.p_prodtyp and " & _
"op.packtyp = nb.p_packtyp " & _
" and op.vernr = nb.p_vernr and nb.active = 'Y' and op.ol_typ in ('XX','CO') and " & _
"sv.gps_planshpdate = " & _
" (select max(sv1.gps_planshpdate) from oes_delsegview sv1, oes_opos op1, " & _
"oes_oposdelseg ds1, oes_nrbom nb1, ncf_comppart cp1 where cp1.item_part_no = " & _
"cp.item_part_no and nb1.c_catnr = cp1.catnr " & _
" and nb1.c_prodtyp = cp1.prodtyp and nb1.c_packtyp = cp1.packtyp and " & _
"nb1.c_vernr = cp1.vernr and sv1.ordnr = ds1.ordnr and sv1.posnr = ds1.posnr and " & _
"sv1.catnr = nb1.p_catnr and sv1.prodtyp = nb1.p_prodtyp and sv1.packtyp = nb1.p_packtyp " & _
" and op1.ordnr = ds1.ordnr and op1.posnr = ds1.posnr and op1.catnr = " & _
"nb1.p_catnr and op1.prodtyp = nb1.p_prodtyp and op1.packtyp = nb1.p_packtyp and op1.vernr " & _
"= nb1.p_vernr and nb1.active = 'Y' and sv1.ord_o_status = '9' and op1.ol_typ in ('XX','CO'))), " 'last_ship_date_manufacturing
Debug.Print SQL
当我计算该表达式时,
SQL
返回一个布尔值,FALSE
。修复字符串连接,使其计算为查询语句,而不是布尔值。当然。。。现在说的很有道理。。。非常感谢。
Dim SQL As String
SQL = SQL & " (select unique sv.gps_planshpdate from oes_delsegview sv, " & _
"oes_opos op, oes_oposdelseg ds, oes_nrbom nb, ncf_comppart cp " & _
"where cp.item_part_no = pd.part_no and nb.c_catnr = cp.catnr and " & _
"nb.c_prodtyp = cp.prodtyp and nb.c_packtyp = cp.packtyp and nb.c_vernr = cp.vernr " & _
" and sv.ordnr = ds.ordnr and sv.posnr = ds.posnr and sv.catnr = nb.p_catnr " & _
"and sv.prodtyp = nb.p_prodtyp and sv.packtyp = nb.p_packtyp and op.ordnr = ds.ordnr " & _
"and op.posnr = ds.posnr and op.catnr = nb.p_catnr and op.prodtyp = nb.p_prodtyp and " & _
"op.packtyp = nb.p_packtyp " & _
" and op.vernr = nb.p_vernr and nb.active = 'Y' and op.ol_typ in ('XX','CO') and " & _
"sv.gps_planshpdate = " & _
" (select max(sv1.gps_planshpdate) from oes_delsegview sv1, oes_opos op1, " & _
"oes_oposdelseg ds1, oes_nrbom nb1, ncf_comppart cp1 where cp1.item_part_no = " & _
"cp.item_part_no and nb1.c_catnr = cp1.catnr " & _
" and nb1.c_prodtyp = cp1.prodtyp and nb1.c_packtyp = cp1.packtyp and " & _
"nb1.c_vernr = cp1.vernr and sv1.ordnr = ds1.ordnr and sv1.posnr = ds1.posnr and " & _
"sv1.catnr = nb1.p_catnr and sv1.prodtyp = nb1.p_prodtyp and sv1.packtyp = nb1.p_packtyp " & _
" and op1.ordnr = ds1.ordnr and op1.posnr = ds1.posnr and op1.catnr = " & _
"nb1.p_catnr and op1.prodtyp = nb1.p_prodtyp and op1.packtyp = nb1.p_packtyp and op1.vernr " & _
"= nb1.p_vernr and nb1.active = 'Y' and sv1.ord_o_status = '9' and op1.ol_typ in ('XX','CO'))), " 'last_ship_date_manufacturing
Debug.Print SQL