经典asp代码中的查询字符串,用于捕获整数值

时间:2012-07-31 07:03:31

标签: asp.net asp-classic vbscript adodb

我写了下面的代码片段,应该根据两个参数

从DB中搜索
  1. 整数值(SHIP的ID)
  2. 字符串值(SHIP名称)。
  3. 但是使用以下代码,我可以使用SHIP名称从DB获取数据,即使用第二种情况。但无法使用SHIP的ID搜索数据。

    以下是代码段。任何有关这些的帮助都非常感谢。

    nIMO = sql_ship_friendly(request.querystring("nIMO"))
    if IsNumeric(nIMO) = false then
        nIMO = ""
    else
        nIMO = cInt(nIMO)
    end if
    
    sVessel = sql_ship_friendly(UCase(request.querystring("sVessel")),10)
    
    
    if not nIMO = "" then   
    
        'search based on vessel id
    
    
    
    
    sql = "SELECT IMO_NBR, VESSEL_NM, COALESCE(SHIP_TYP,'0') AS SHIP_TYP, COALESCE(DWT_WT, 0) AS DWT_WT, COALESCE(YEAR_BUILT_NBR, 0) AS YEAR_BUILT_NBR FROM RSP_VESSEL_VW WHERE ACTIVE_IND='Y' AND IMO_NBR = 7723948"
        Set db1 = Server.CreateObject("ADODB.Connection")
        db1.Open GV_VIEW_DB_String 
        Set rs = db1.Execute(sql)
        Set dbl = nothing "
    
    elseif not sVessel = "" then
    
        'search based on vessel number
    
    
    sql = "SELECT IMO_NBR, VESSEL_NM,  COALESCE(SHIP_TYP,'0') AS SHIP_TYP, COALESCE(DWT_WT, 0) AS DWT_WT, COALESCE(YEAR_BUILT_NBR , 0) AS YEAR_BUILT_NBR FROM RSP_VESSEL_VW WHERE VESSEL_NM LIKE '"&SVESSEL&"%' AND ACTIVE_IND='Y'"
    
      

    'response.write sql设置db1 =   Server.CreateObject(“ADODB.Connection”)db1.Open GV_VIEW_DB_String         设置rs = db1.Execute(sql)设置dbl = nothing

2 个答案:

答案 0 :(得分:0)

如果您的第一个案例是

  

sql =“选择IMO_NBR,VESSEL_NM,COALESCE(SHIP_TYP,'0')AS SHIP_TYP,   COALESCE(DWT_WT,0)AS DWT_WT,COALESCE(YEAR_BUILT_NBR,0)AS   YEAR_BUILT_NBR来自RSP_VESSEL_VW WHERE ACTIVE_IND ='Y'和IMO_NBR =   7723948"

但我可以看到您在查询中使用 nIMO 参数。把它,你应该得到结果..

您可以像AND IMO_NBR = nIMO一样使用它。

答案 1 :(得分:0)

问题是您的SQL语句中没有使用nIMO变量作为搜索条件的位置。忘记使用IsNumeric(nIMO)= false ...改用isNull函数。试试这个。

if not isnull( request.querystring("nIMO")) then
    nIMO = cInt(nIMO)
    sql = "SELECT IMO_NBR, VESSEL_NM, COALESCE(SHIP_TYP,'0') AS SHIP_TYP," &_
          "COALESCE(DWT_WT, 0) AS DWT_WT, COALESCE(YEAR_BUILT_NBR, 0) AS " &_
          "YEAR_BUILT_NBR FROM RSP_VESSEL_VW WHERE ACTIVE_IND='Y' AND " &_
          "IMO_NBR =" & nIMO
    ...
    ...
    ...
 end if