我不是 SQL 专家,并且在我的一些现有经典 asp 代码中发现了一个错误,因此它不能在所有情况下工作。我希望有一些出色的 sql 经验的人可以帮助我编写更复杂的情况,即两种情况都发生时
If intItemType = SV_ITEM_TYPE_MATRIX
然后使用这部分 SQL
LEFT OUTER JOIN usd_matrixSets MS " &_
"ON MS.itemID = SI.itemID " &_
但是当intItemType <> SV_ITEM_TYPE_MATRIX
它被忽略时。
如您所见,我已经为两种/或两种情况编写了代码,但这实际上并没有涵盖两种情况都可能发生的情况。
这是代码:
If intItemType = SV_ITEM_TYPE_MATRIX Then
strSQL = "SELECT SI.itemID, itemType, itemText, minimumValue, maximumValue, dataType, MS.matrixSetType, MS.matrixSetID " &_
"FROM usd_SurveyItem SI " &_
"LEFT OUTER JOIN usd_matrixSets MS " &_
"ON MS.itemID = SI.itemID " &_
"WHERE surveyID = " & intSurveyID &_
" AND itemType " &_
"In(" & SV_ITEM_TYPE_TEXTAREA & "," &_
SV_ITEM_TYPE_SINGLE_LINE & "," &_
SV_ITEM_TYPE_DATE & "," &_
SV_ITEM_TYPE_CHECKBOXES & "," &_
SV_ITEM_TYPE_RADIO & "," &_
SV_ITEM_TYPE_DROPDOWN & "," &_
SV_ITEM_TYPE_MATRIX & "," &_
SV_ITEM_TYPE_UPLOAD_FILE & ")" &_
" AND pageID = " & intPageNumber &_
" ORDER BY pageID, SI.orderByID "
else
strSQL = "SELECT SI.itemID, itemType, itemText, minimumValue, maximumValue, dataType" &_
" FROM usd_SurveyItem SI " &_
"WHERE surveyID = " & intSurveyID &_
" AND itemType " &_
"In(" & SV_ITEM_TYPE_TEXTAREA & "," &_
SV_ITEM_TYPE_SINGLE_LINE & "," &_
SV_ITEM_TYPE_DATE & "," &_
SV_ITEM_TYPE_CHECKBOXES & "," &_
SV_ITEM_TYPE_RADIO & "," &_
SV_ITEM_TYPE_DROPDOWN & "," &_
SV_ITEM_TYPE_MATRIX & "," &_
SV_ITEM_TYPE_UPLOAD_FILE & ")" &_
" AND pageID = " & intPageNumber &_
" ORDER BY pageID, SI.orderByID "
end if
我的问题是,有时我的数据库中同时拥有 SV_ITEM_TYPE_MATRIX 和其他人。我怎样才能重写这段代码?