我想在最后更改标准。到过去的20天。 这是 ? (DateTime.Now.Year) - 20?
sqlT1 = "SELECT ROW_NUMBER() OVER(ORDER BY ID_KEY DESC) AS RN,* From(Select distinct f.FACILITY_NAME, ID_KEY, [BATCH] AS column1, [IMPORTDATE], [DATEBILLED], [RX], [DATEDISPENSED], [DAYSUPPLY], [PAYTYPE], [NPI], [PHYSICIAN], [COST], [QUANTITY], [MEDICATION], A.[NDC], " +
" case when (COST > 0 AND DAYSUPPLY > 0) then (COST / DAYSUPPLY) * 30 else 0 end [30DayCost] , [PATIENTNAME], [ROUTEOFADMIN], [INVOICECAT], [COPAY], [BRAND], [TIER], [SKILLLEVEL], [STAT] STATUS, [LASTTASKDATE],SEQNO, 'please bring to the attention of the administrator.' SUBST_INSTRUCTIONS , f.FACILITY_ID " +
" FROM [LMI].[T_CHARGES] A Left Outer Join PBM.FACILITY f on A.FACILITYNPI = f.FACILITY_NPI " +
" Where COST > 500 " +
" AND [TIER] = 'T1' and month(A.DATEDISPENSED) = " + DateTime.Now.Month + " and year(A.DATEDISPENSED) = " + DateTime.Now.Year + "" +
sqlWhere + " AND f.FACILITY_ID IN (" + selected + ")";
答案 0 :(得分:1)
我不知道如何为您更改代码,但通常在SQL中使用getdate()
来获取今天的日期,并且您使用dateadd(d,-20,getdate())
来获取20天前的代码使用
(T-SQL):
testingdate between dateadd(d,-20,getdate()) and getdate()
在你的where子句中
答案 1 :(得分:0)
要获取20天前的日期,您可以使用sql函数DATEADD:
WHERE A.DATEDISPENSED >= DATEADD(dd,-20,GetDate())