1、语句查询时传入一个参数 type 怎么进行判断 type=车间执行车间相关语句 type=办公楼执行办公楼的语句
2、如果参数不等与 车间或办公楼执行 另外一个语句
SELECT '车间楼' AS '名称',ISNULL(SUM(Rd_Data),0) AS '能耗' FROM EQ_RealTimeCodeHourData WHERE CONVERT(varchar(13), Rd_LTime, 120) ='${Year_Month_Date}'+' '+RIGHT('0' +'${Hour}',2)AND Rd_Code IN ('AKA242010019')
---------
SELECT '办公楼' AS '名称',ISNULL(SUM(Rd_Data),0) AS '能耗' FROM EQ_RealTimeCodeHourData WHERE CONVERT(varchar(13), Rd_LTime, 120) ='${Year_Month_Date}'+' '+RIGHT('0' +'${Hour}',2)AND Rd_Code IN ('AKX242010062')
${if(type='车间执行',"SELECT '车间楼' AS '名称',ISNULL(SUM(Rd_Data),0) AS '能耗' FROM EQ_RealTimeCodeHourData WHERE CONVERT(varchar(13), Rd_LTime, 120) ='"+Year_Month_Date+"'+' '+RIGHT('0' +'"+Hour+"',2) AND Rd_Code IN ('AKA242010019')",if(type='办公楼',"SELECT '办公楼' AS '名称',ISNULL(SUM(Rd_Data),0) AS '能耗' FROM EQ_RealTimeCodeHourData WHERE CONVERT(varchar(13), Rd_LTime, 120) ='"+Year_Month_Date+"'+' '+RIGHT('0' +'"+Hour+"',2) AND Rd_Code IN ('AKX242010062')",""))}
${if(type="车间执行","SELECT '车间楼' AS '名称',ISNULL(SUM(Rd_Data),0) AS '能耗' FROM EQ_RealTimeCodeHourData WHERE CONVERT(varchar(13), Rd_LTime, 120) ='"+Year_Month_Date+"'"+' '+"RIGHT('0' +'"+Hour+"',2)AND Rd_Code IN ('AKA242010019')",if(type="办公楼执行","SELECT '办公楼' AS '名称',ISNULL(SUM(Rd_Data),0) AS '能耗' FROM EQ_RealTimeCodeHourData WHERE CONVERT(varchar(13), Rd_LTime, 120) ='"+Year_Month_Date+"'"+' '+"RIGHT('0' +'"+Hour+"',2)AND Rd_Code IN ('AKX242010062')","其他SQL"))}
snrtuemc 回复 SSVIP(提问者)那试试,${if(type="车间执行","SELECT '车间楼' AS '名称',ISNULL(SUM(Rd_Data),0) AS '能耗' FROM EQ_RealTimeCodeHourData WHERE CONVERT(varchar(13), Rd_LTime, 120) ='"+Year_Month_Date+"'"+' '+RIGHT('0' +'"+Hour+"',2)AND Rd_Code IN ('AKA242010019')",if(type="办公楼执行","SELECT '办公楼' AS '名称',ISNULL(SUM(Rd_Data),0) AS '能耗' FROM EQ_RealTimeCodeHourData WHERE CONVERT(varchar(13), Rd_LTime, 120) ='"+Year_Month_Date+"'"+' '+RIGHT('0' +'"+Hour+"',2)AND Rd_Code IN ('AKX242010062')","其他SQL"))}
${if(type="车间","SELECT '车间楼' AS '名称',ISNULL(SUM(Rd_Data),0) AS '能耗' FROM EQ_RealTimeCodeHourData WHERE CONVERT(varchar(13), Rd_LTime, 120) ='"+Year_Month_Date+"'+' '+RIGHT('0' +'"+Hour+"',2)AND Rd_Code IN ('AKA242010019')",type="办公楼","SELECT '办公楼' AS '名称',ISNULL(SUM(Rd_Data),0) AS '能耗' FROM EQ_RealTimeCodeHourData WHERE CONVERT(varchar(13), Rd_LTime, 120) ='"+Year_Month_Date+"'+' '+RIGHT('0' +'"+Hour+"',2)AND Rd_Code IN ('AKX242010062')","sq3")}
,ISNULL(SUM(Rd_Data),0) AS '能耗' FROM EQ_RealTimeCodeHourData WHERE CONVERT(varchar(13), Rd_LTime, 120) ='${Year_Month_Date}'+' '+RIGHT('0' +'${Hour}',2)AND Rd_Code IN ('AKA242010019')