根据日期范围检索数据

时间:2018-09-26 16:53:27

标签: sql-server coldfusion

我有以下查询,该查询根据用户名,医院名称,处理日期和出院日期检索用户信息。但是,查询的处理日期和出库日期部分无法按预期方式工作。两者都是datetime类型。

以下是查询,它将检查输入的用户日期范围(以及其他输入),并查看记录是否存在:

<cfif isDefined("form.FirstName") AND isDefined("form.LastName") AND isDefined("form.Hosp") AND isDefined("form.FromDischargeDt") 
AND isDefined("form.ToDischargeDt") AND isDefined("form.FromProcessDt") AND isDefined("form.ToDProcessDt") AND form.Hosp NEQ "Particular Hospital Name">

    <cftransaction>

        <cfquery name="HospitalVisits1" datasource="source">
            SELECT First_Name, 
                   Last_Name, 
                   DOB, 
                   Sex, 
                   Service, 
                   Service_Desc, 
                   Service_Dt, 
                   Admit_Dt, 
                   Phone, 
                   Address1, 
                   Address2, 
                   City, 
                   State, 
                   Zip, 
                   Account, 
                   Hosp_Name,
                   MR_Number, 
                   Insurance, 
                   Plan_Name, 
                   Policy_No, 
                   Group_No, 
                   Reason_For_Visit, 
                   Process_Dt,
                   Discharge_Dt,
                   [Pt Class] as PtClass
            FROM Hospital_Data
            WHERE 
                First_Name like <cfqueryparam value="%#FName#%" cfsqltype="cf_sql_varchar">
            AND
                Last_Name like <cfqueryparam value="%#LName#%" cfsqltype="cf_sql_varchar">
            AND
                Hosp_Name like <cfqueryparam value="%#Hosp#%" cfsqltype="cf_sql_varchar">
            <!---AND 
                Process_Dt >= <cfqueryparam value="#fromProcessDt#" cfsqltype="cf_sql_datetime">
            AND 
                Process_Dt <= <cfqueryparam value="#toProcessDt#" cfsqltype="cf_sql_datetime">
            AND 
                Discharge_Dt >= <cfqueryparam value="#fromdischargeDt#" cfsqltype="cf_sql_datetime">
            AND 
                Discharge_Dt <= <cfqueryparam value="#todischargeDt#" cfsqltype="cf_sql_datetime">--->
            <!---AND 
                Process_Dt between <cfqueryparam value="#fromProcessDt#" cfsqltype="cf_sql_datetime"> and <cfqueryparam value="#toProcessDt#" cfsqltype="cf_sql_datetime">
            AND
                Discharge_Dt between <cfqueryparam value="#fromdischargeDt#" cfsqltype="cf_sql_datetime"> and <cfqueryparam value="#todischargeDt#" cfsqltype="cf_sql_datetime">--->
                <!---AND
                Hosp_Name like <cfqueryparam value="%#BirthDt#%" cfsqltype="cf_sql_varchar">--->
        </cfquery>

        <!---<cfdump var="#HospitalVisits1#">
        <cfabort>--->
    </cftransaction>

如果记录存在,我将显示结果(将显示的示例):

<span style="color:red">Process Date(s)</span>:
    <!--- create the struct --->
    <cfset processDtStruct = StructNew()>
    <cfset c1 = 1>  

    <cfloop index="processDt" list="#valuelist(HospitalVisits1.Process_Dt, "|")#" delimiters="|">
        <cfset processDtStruct[processDt] = "" > 
    </cfloop>

    <cfset newProcessList = StructKeyList(processDtStruct)>

    <cfloop index="i" list="#newProcessList#">
        <cfoutput>
            &nbsp;#DateFormat(i,"mm/dd/yyyy")#<cfif c LT listlen(newProcessList)>,</cfif>   <cfset c++>
        </cfoutput>
    </cfloop><br />

在这里设置我从用户输入中获得的值

<cfif isDefined("form.FromDischargeDt")>
    <cfset fromdischargeDt = DateFormat(form.FromDischargeDt, "yyyy-m-dd") />
<cfelse>
    <cfset fromdischargeDt = "" />
</cfif> 

<cfif isDefined("form.ToDischargeDt")>
    <cfset todischargeDt = DateFormat(form.ToDischargeDt, "yyyy-m-dd") />
<cfelse>
    <cfset todischargeDt = "" />
</cfif> 

<cfif isDefined("form.FromProcessDt")>
    <cfset fromProcessDt = DateFormat(form.FromProcessDt, "yyyy-m-dd") />
<cfelse>
    <cfset fromProcessDt = "" />
</cfif> 

<cfif isDefined("form.ToDProcessDt")>
    <cfset toProcessDt = DateFormat(form.ToDProcessDt, "yyyy-m-dd") />
<cfelse>
    <cfset toProcessDt = "" />
</cfif> 

以下是我使用的获取日期范围的表格示例:

enter image description here

以下是数据示例:

2]

任何帮助将不胜感激

0 个答案:

没有答案