如何将此SQL代码转换为经典的ASP / VB代码

时间:2017-05-19 16:38:58

标签: sql vb.net asp-classic

我需要修改由我的前任创建的现有经典ASP Web应用程序的一些代码。

当前代码:

sql = "SELECT * FROM (SELECT substr(trim(WURK_SUMMARY.WORK_ORD_NO),-4,4) LF, LREQ.PROCESS_CENTER, WURK_SUMMARY.WORK_ORD_NO As ORDER_NO, WURK_SUMMARY.ORIG_DT, WURK_SUMMARY.PART_DESC, WURK_SUMMARY.ROUT_PART_DESC, WURK_SUMMARY.BASE_TRAK_ID, WURK_SUMMARY.ROUT_PART_NO, WURK_SUMMARY.COMBINE_NO, "

sql = sql & "WURK_SUMMARY.WO_STATUS_DESC, WURK_SUMMARY.REQD_DT, WURK_SUMMARY.ACT_START_DT, WURK_SUMMARY.RLSE_DT, WURK_SUMMARY.CLOSE_DT, WURK_SUMMARY.ACT_CMPL_DT, WURK_SUMMARY.LOAD_HOURS, WURK_SUMMARY.ACTUAL_HOURS, "

sql = sql & "ROW_NUMBER() OVER (PARTITION BY WURK_SUMMARY.WORK_ORD_NO ORDER BY WURK_SUMMARY.WORK_ORD_NO) AS RowNUMBR FROM WURK_SUMMARY JOIN LREQ ON WURK_SUMMARY.WORK_ORD_NO=LREQ.ORDER_NO WHERE "

    if use_work_ord_no=true then
    sql = sql & "WURK_SUMMARY.WORK_ORD_NO LIKE '"&mln&"-%' "
    else
    sql = sql & "WURK_SUMMARY.COMBINE_NO='"&mln&"' "
    end if

    sql = sql & "AND LREQ.PROCESS_CENTER='"&process_center&"' "

要添加到上面代码的SQL代码:

AND LREQ.SEQ_NO = 
        (SELECT MIN(LREQ2B.SEQ_NO)
            FROM LREQ AS LREQ2B
            WHERE LREQ.ORDER_NO = LREQ2B.ORDER_NO
            AND LREQ.TRAK_ID = LREQ2B.TRAK_ID)

1 个答案:

答案 0 :(得分:-1)

这里有一个清理过的裂缝:

sql = "SELECT * FROM (SELECT substr(trim(WURK_SUMMARY.WORK_ORD_NO),-4,4) LF, LREQ.PROCESS_CENTER, WURK_SUMMARY.WORK_ORD_NO As ORDER_NO, WURK_SUMMARY.ORIG_DT, WURK_SUMMARY.PART_DESC, WURK_SUMMARY.ROUT_PART_DESC, WURK_SUMMARY.BASE_TRAK_ID, WURK_SUMMARY.ROUT_PART_NO, WURK_SUMMARY.COMBINE_NO, " _
& "WURK_SUMMARY.WO_STATUS_DESC, WURK_SUMMARY.REQD_DT, WURK_SUMMARY.ACT_START_DT, WURK_SUMMARY.RLSE_DT, WURK_SUMMARY.CLOSE_DT, WURK_SUMMARY.ACT_CMPL_DT, WURK_SUMMARY.LOAD_HOURS, WURK_SUMMARY.ACTUAL_HOURS, " _
& "ROW_NUMBER() OVER (PARTITION BY WURK_SUMMARY.WORK_ORD_NO ORDER BY WURK_SUMMARY.WORK_ORD_NO) AS RowNUMBR FROM WURK_SUMMARY JOIN LREQ ON WURK_SUMMARY.WORK_ORD_NO=LREQ.ORDER_NO WHERE "

if use_work_ord_no=true then
    sql = sql & "WURK_SUMMARY.WORK_ORD_NO LIKE '"&mln&"-%' "
else
    sql = sql & "WURK_SUMMARY.COMBINE_NO='"&mln&"' "
end if

sql = sql & "AND LREQ.PROCESS_CENTER='"&process_center&"' " _
& "AND LREQ.SEQ_NO = " _
& " (SELECT MIN(LREQ2B.SEQ_NO) " _
& "     FROM LREQ AS LREQ2B " _
& "     WHERE LREQ.ORDER_NO = LREQ2B.ORDER_NO " _
& "        AND LREQ.TRAK_ID = LREQ2B.TRAK_ID) "