有麻烦替换/**评论**/与其他东西在我的javascript和sql

Having trouble replacing /**comment**/ with something else in my javascript and sql

本文关键字:我的 javascript sql 其他 替换 麻烦 评论      更新时间:2023-09-26

我试图用javascript替换sql查询中的注释。我的sql查询是这样的:

    select round(sum(case when date_part('month', fd.fs_dt) = 1 and date_part('year', fd.fs_dt) = /**year**/ then amount end)::numeric, 0) January_data
from this_table

我的javascript查询是这样的

if (params["This_year"] == "1/1/14"){
this.querytext = this.queryText.replace("/**year**/", "2014")}
else if (params["This_year"] == "1/1/15"){
this.querytext = this.queryText.replace("/**year**/", "2015")}

在'then'或'then'附近出现错误

代码实际上并没有替换任何东西,因为您将替换的结果分配给了一个新变量(querytext而不是queryText)。