2015-02-11 96 views
-2

我想在asp中编写一个“if”语句来以正确的格式获取我需要在高图表中提供的数据。ASP IF语句获取数据

问题1:你们能让我知道我的if语句有什么问题吗? 问题2:如果我想要添加另一个数据集以在条件0的另一个图表中进行填充,那么我如何在asp中引用它?我在哪里放置另一个sql语句?

condition = Split(Request.Form("condition"),"~") 
    'condition = Split("field1~field2~field3~('field4')~('')~('Field5')~'01/18/2015' and '02/02/2015'~field6", "~") 

    '0 is the chart type 
    '1 is chart frequency 
    '2 company 
    '3 is place 
    '4 is shop 
    '5 is caused 
    '6 is date range' 
    '7is top5 type' 
    'field7~('')~('')~('')~01/18/2015<>01/18/2015~field8' 


'' Response.write condition(3) 

    chartinfo = condition(2) 
    dateString = "" 

    if condition(0)<>"Top 5" then 
     where = "[Type]='" + condition(1) +"'" 

     if condition(1)<> "Monthly" then 
      where = where + " and convert(datetime,date,101) between " + condition(6) 
     end if 
     if condition(3) <>"('')" then 
      where = where + " and place in " + condition(3) 
      chartinfo = chartinfo + ";" + condition(3) 
     end if 
     if condition(4) <>"('')" then 
      where = where + " and Shop in " + condition(4) 
      chartinfo = chartinfo + ";" + condition(4) 
     end if 
     if condition(5) <>"('')" then 
      where = where + " and [Caused Group] in " + condition(5) 
      chartinfo = chartinfo + ";" + condition(5) 
     end if 

    else 
     condition(0) = "Top 5" then 
     where 
    end if 

    where = replace(where,"'","''") 

    sql = "[Data] '" + where + "', '''" + dateString +"''','''"+ chartinfo +"'''" 
+1

1.在东西'​​else'地方怪异。可能是'elseif condition(0)=“Top 5”then“或者保留'else'并且注释''''condition(0)=”Top 5“then line。你是什​​么意思分开'where'?适当的缩进应该有所帮助。 – JosefZ 2015-02-11 09:22:11

+0

xcuse - 如此脏的代码 – DimaSUN 2015-02-11 21:17:09

回答

0
where = "[Type]='" + condition(1) +"'" 
--> 
where = " where [Type] = '" + condition(1) +"'" 

..skip.. 

else 
    condition(0) = "Top 5" then 
    where 
--> 

else 
' condition(0) = "Top 5" then 
    where = "" 
+0

我认为这个答案可能会更好一点,如果你给你正在使用的代码的上下文。你是否试图建议替代目前的线? – Matt 2015-02-12 02:23:39