我在SQL Server 2012中有一个大型数据库系统和一个用ASP编写的前端界面。用户可以查询数据库,我也有一个字典来获取拼写错误和备用拼写。
历史上,用户可以进行单个单词搜索,也可以进行多字AND或OR搜索。我刚刚完成了一个精确的多字搜索,搜索包括字典中的多个变体。
在下面的例子中,我正在寻找各个领域的“笔画单元”或“storke单元”。请注意,工作版本是我从非工作版本的输出中剪切和粘贴的文本,通常不存在。对于陈述的长度抱歉,我只有很多要搜索的字段。 AND和OR搜索有更长的语句,但我从来没有遇到任何问题。
我完全不知道为什么一个版本有效,而另一个版本没有,所以对任何提示都会感激不尽。 (我通常也没有错误检查连接语句的每一行,我只是希望可能出现一些内容)
我的代码目前正在
Err.Clear
LineOut("Version 1: Not working")
Session("Version1")="INSERT INTO dbo.Temp_RCT_Existing_Results "+Session("DORIS_RCT_SEL")+Session("DORIS_RCT_FROM2")+" ORDER BY Acronym, Year DESC, Authors, Title"
LineOut("<BR>-<BR>["+Session("Version1")+"]")
SET conn =Server.CreateObject("ADODB.Connection")
LineOut("Error Number on Create ="+CStr(Err.Number))
conn.Open adserverlocn
LineOut("Error Number on Open="+CStr(Err.Number))
conn.Execute Session("Version1")
LineOut("Error Number on Execute="+CStr(Err.Number))
conn.Close
SET conn=Nothing
LineOut("<BR>-<BR>Version 2: Working")
Session("Version2")="SELECT DISTINCT REF.REF_ID AS RefID, REF.REF_LTITLE AS Title, REF.REF_AUTHRS AS Authors, REF.REF_YEAR AS Year, STUDY.ST_ACRONYM AS Acronym, REF.REF_CITATION AS Citation,REF.REF_URL,REF.REF_PUBID, STUDY.ST_INTDTLS AS StudyDets, STUDY.ST_ISRCTN ,STUDY.ST_NCT, STUDY.ST_Registers,STUDY.ST_UKCRN,STUDY.ST_NAME,STUDY.ST_SYSREV,STUDY.ST_STATUS,REF.REF_DORIS_ORDER, 'Bob2' AS BelongsTo,ST_DOI, '2016-11-08' AS SearchDate, STUDY.ST_SIZE, REF_ORTITL AS OTitle FROM INTERV INNER JOIN ST_INT ON INTERV.INT_ID = ST_INT.[INT] INNER JOIN STUDY ON ST_INT.ST = STUDY.STUDY_ID INNER JOIN REF_ST ON STUDY.STUDY_ID = REF_ST.ST INNER JOIN REF ON REF_ST.REF = REF.REF_ID WHERE STUDY.ST_CONFID='OPEN' AND REF.REF_PUBSTA='PUBLISHED' AND (((REF.REF_LTITLE LIKE '%stroke UNIT %' OR STUDY.ST_INTDTLS LIKE '%stroke UNIT %' OR INTERV.INT_METHOD LIKE '%stroke UNIT %' OR INTERV.INT_CODE1 LIKE '%stroke UNIT %' OR INTERV.INT_CODE2 LIKE '%stroke UNIT %' OR INTERV.INT_CODE3 LIKE '%stroke UNIT %' OR INTERV.INT_CODE4 LIKE '%stroke UNIT %' OR INTERV.INT_DISEASE LIKE '%stroke UNIT %' OR INTERV.INT_CONDITION LIKE '%stroke UNIT %')) OR ((REF.REF_LTITLE LIKE '%storke UNIT %' OR STUDY.ST_INTDTLS LIKE '%storke UNIT %' OR INTERV.INT_METHOD LIKE '%storke UNIT %' OR INTERV.INT_CODE1 LIKE '%storke UNIT %' OR INTERV.INT_CODE2 LIKE '%storke UNIT %' OR INTERV.INT_CODE3 LIKE '%storke UNIT %' OR INTERV.INT_CODE4 LIKE '%storke UNIT %' OR INTERV.INT_DISEASE LIKE '%storke UNIT %' OR INTERV.INT_CONDITION LIKE '%storke UNIT %'))) AND (Study.st_sysrev='-') AND (study.st_status='COMPLETED')"
Session("Version2")="INSERT INTO dbo.Temp_RCT_Existing_Results "+Session("Version2")+" ORDER BY Acronym, Year DESC, Authors, Title"
LineOut("<BR>-<BR>["+Session("Version2")+"]")
SET conn =Server.CreateObject("ADODB.Connection")
conn.Open adserverlocn
conn.Execute Session("Version2")
conn.Close
SET conn=Nothing
此输出为
第1版:无效
INSERT INTO DBO.temp_rct_existing_results
SELECT DISTINCT ref.ref_id AS RefID,
ref.ref_ltitle AS Title,
ref.ref_authrs AS Authors,
ref.ref_year AS Year,
study.st_acronym AS Acronym,
ref.ref_citation AS Citation,
ref.ref_url,
ref.ref_pubid,
study.st_intdtls AS StudyDets,
study.st_isrctn,
study.st_nct,
study.st_registers,
study.st_ukcrn,
study.st_name,
study.st_sysrev,
study.st_status,
ref.ref_doris_order,
'Bob' AS BelongsTo,
st_doi,
'2016-11-08' AS SearchDate,
study.st_size,
ref_ortitl AS OTitle
FROM interv
INNER JOIN st_int
ON interv.int_id = st_int.[int]
INNER JOIN study
ON st_int.st = study.study_id
INNER JOIN ref_st
ON study.study_id = ref_st.st
INNER JOIN ref
ON ref_st.ref = ref.ref_id
WHERE study.st_confid = 'OPEN'
AND ref.ref_pubsta = 'PUBLISHED'
AND ( (( ref.ref_ltitle LIKE '%stroke UNIT %'
OR study.st_intdtls LIKE '%stroke UNIT %'
OR interv.int_method LIKE '%stroke UNIT %'
OR interv.int_code1 LIKE '%stroke UNIT %'
OR interv.int_code2 LIKE '%stroke UNIT %'
OR interv.int_code3 LIKE '%stroke UNIT %'
OR interv.int_code4 LIKE '%stroke UNIT %'
OR interv.int_disease LIKE '%stroke UNIT %'
OR interv.int_condition LIKE '%stroke UNIT %' ))
OR (( ref.ref_ltitle LIKE '%storke UNIT %'
OR study.st_intdtls LIKE '%storke UNIT %'
OR interv.int_method LIKE '%storke UNIT %'
OR interv.int_code1 LIKE '%storke UNIT %'
OR interv.int_code2 LIKE '%storke UNIT %'
OR interv.int_code3 LIKE '%storke UNIT %'
OR interv.int_code4 LIKE '%storke UNIT %'
OR interv.int_disease LIKE '%storke UNIT %'
OR interv.int_condition LIKE '%storke UNIT %' )) )
AND ( study.st_sysrev = '-' )
AND ( study.st_status = 'COMPLETED' )
ORDER BY acronym,
year DESC,
authors,
title
Create = 0
上的错误号打开时的错误编号= 0
执行错误号= 0
第2版:工作
INSERT INTO DBO.temp_rct_existing_results
SELECT DISTINCT ref.ref_id AS RefID,
ref.ref_ltitle AS Title,
ref.ref_authrs AS Authors,
ref.ref_year AS Year,
study.st_acronym AS Acronym,
ref.ref_citation AS Citation,
ref.ref_url,
ref.ref_pubid,
study.st_intdtls AS StudyDets,
study.st_isrctn,
study.st_nct,
study.st_registers,
study.st_ukcrn,
study.st_name,
study.st_sysrev,
study.st_status,
ref.ref_doris_order,
'Bob2' AS BelongsTo,
st_doi,
'2016-11-08' AS SearchDate,
study.st_size,
ref_ortitl AS OTitle
FROM interv
INNER JOIN st_int
ON interv.int_id = st_int.[int]
INNER JOIN study
ON st_int.st = study.study_id
INNER JOIN ref_st
ON study.study_id = ref_st.st
INNER JOIN ref
ON ref_st.ref = ref.ref_id
WHERE study.st_confid = 'OPEN'
AND ref.ref_pubsta = 'PUBLISHED'
AND ( (( ref.ref_ltitle LIKE '%stroke UNIT %'
OR study.st_intdtls LIKE '%stroke UNIT %'
OR interv.int_method LIKE '%stroke UNIT %'
OR interv.int_code1 LIKE '%stroke UNIT %'
OR interv.int_code2 LIKE '%stroke UNIT %'
OR interv.int_code3 LIKE '%stroke UNIT %'
OR interv.int_code4 LIKE '%stroke UNIT %'
OR interv.int_disease LIKE '%stroke UNIT %'
OR interv.int_condition LIKE '%stroke UNIT %' ))
OR (( ref.ref_ltitle LIKE '%storke UNIT %'
OR study.st_intdtls LIKE '%storke UNIT %'
OR interv.int_method LIKE '%storke UNIT %'
OR interv.int_code1 LIKE '%storke UNIT %'
OR interv.int_code2 LIKE '%storke UNIT %'
OR interv.int_code3 LIKE '%storke UNIT %'
OR interv.int_code4 LIKE '%storke UNIT %'
OR interv.int_disease LIKE '%storke UNIT %'
OR interv.int_condition LIKE '%storke UNIT %' )) )
AND ( study.st_sysrev = '-' )
AND ( study.st_status = 'COMPLETED' )
ORDER BY acronym,
year DESC,
authors,
title
如果我剪切并将非工作版本发布到SQL Server Management Studio中,它将完美运行。我还交换了工作版本和非工作版本的顺序,看它是否有所不同。
非常感谢提前。