sql语句如何用if等判断?语法?用JS脚本的举个例!

JavaScript017

sql语句如何用if等判断?语法?用JS脚本的举个例!,第1张

应该写成

var sql1="select * from shujubiao"

var sql2=" where xuhao like "+"'%"+xhao+"%' or xingming like '%"+xhao+"%' or yuwen like '%"+xhao+"%' or

shuxue like '%"+xhao+"%'"

if(a==""){

sql=sql1

}else{

sql=sql1+sql2

}

你的sql2的where前面少了一个空格,另外,变量不要用双引号

资料:网页链接

javascript中判断字符串是否以指定字符串开始或结尾:

//判断当前字符串是否以str开始 先判断是否存在function是避免和js原生方法冲突,自定义方法的效率不如原生的高

if (typeof String.prototype.startsWith != 'function') {

   String.prototype.startsWith = function (str){         

      return this.slice(0, str.length) == str

   }

}

//判断当前字符串是否以str结束

if (typeof String.prototype.endsWith != 'function') {

 String.prototype.endsWith = function (str){          

  return this.slice(-str.length) == str

 }

}    

     

//测试程序

var sCompareStr = "select * from t1"//比较字符串

var sBeCompareStr = ""//被比较字符串

if(sCompareStr.endsWith(sBeCompareStr)){//这里可以替换为startsWith

    alert(sCompareStr+" 是以:"+sBeCompareStr+" 结束")

}else{

    alert(sCompareStr+" 不是以:"+sBeCompareStr+" 结束")

    sCompareStr +=sBeCompareStr //若无分号,将分号加到后面

}

这样书写的原因:

之所以在将整个代码放在if判断中是因为避免以后原生的js版本中增加了同类方法而导致代码效率降低。因为对于同名方法来说,js原生的代码效率要高于用户自己扩展的方法

之所以使用slice方法而不使用indexof方法,是由于indexof方法在处理较长的字符串时效率比较低

这个可以搬过去用,楼主若觉得回答有所帮助,望采纳,谢谢!

调用FineRepor的内置公式:FR.remoteEvaluate("具体公式"),返回值为:这个具体公式的结果。

例如:var a = FR.remoteEvaluate("sum(1+2)")

这时变量a的值就是3了。

这里要注意的是,由于在SQL函数中,需要多次用到双引号("),所以大家要注意用反斜杠(\)进行转义:var sql = "SQL(\"FRDemo\",\"Select count(*) fromsales_basic\",1,1)"

或者为了降低转义带来的复杂度,可以写成如下格式:var sql="select count(*) from sales_basic"varres=FR.remoteEvaluate('sql("FRDemo","'+sql+'",1,1)')