我的代码可以运行,但是很糟糕。有没有办法以适当的方式清除此代码?
此代码(存储的proc)用于在一个表中的不同列中搜索单词,以及具有不同卷名(0-4)的帖子
@searchval nvarchar(500),
@arrStatusTyp int,
@rolltypAdmin int,
@roll1 int,
@roll2 int,
@roll3 int,
@roll4 int,
@visningsperiod nvarchar(4)
SELECT kk_aj_tbl_Arrangemang.ArrID
FROM kk_aj_tbl_content INNER JOIN
kk_aj_tbl_arridtoContent ON kk_aj_tbl_content.Contentid = kk_aj_tbl_arridtoContent.contentid INNER JOIN
kk_aj_tbl_Arrangemang ON kk_aj_tbl_arridtoContent.arrid = kk_aj_tbl_Arrangemang.ArrID INNER JOIN
kk_aj_tbl_ArrangemangStatus ON kk_aj_tbl_Arrangemang.ArrangemangStatusID = kk_aj_tbl_ArrangemangStatus.ArrangemangStatusID INNER JOIN
kk_aj_tbl_Konstformtyp ON kk_aj_tbl_Arrangemang.KonstformID = kk_aj_tbl_Konstformtyp.KonstformID INNER JOIN
Users ON kk_aj_tbl_Arrangemang.AdminuserID = Users.UserID INNER JOIN
kk_aj_tbl_utovare ON kk_aj_tbl_Arrangemang.UtovarID = kk_aj_tbl_utovare.UtovarID
WHERE
(kk_aj_tbl_Arrangemang.ArrangemangStatusID = @arrStatusTyp) AND (kk_aj_tbl_arridtoContent.Version=1) AND
(
(kk_aj_tbl_content.Rubrik LIKE '%'+@searchval+'%') AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll1) OR
(kk_aj_tbl_content.Rubrik LIKE '%'+@searchval+'%') AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll2) OR
(kk_aj_tbl_content.Rubrik LIKE '%'+@searchval+'%') AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll3) OR
(kk_aj_tbl_content.Rubrik LIKE '%'+@searchval+'%') AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll4) OR
(kk_aj_tbl_content.Underrubrik LIKE '%'+@searchval+'%')AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll1) OR
(kk_aj_tbl_content.Underrubrik LIKE '%'+@searchval+'%')AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll2) OR
(kk_aj_tbl_content.Underrubrik LIKE '%'+@searchval+'%')AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll3) OR
(kk_aj_tbl_content.Underrubrik LIKE '%'+@searchval+'%')AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll4) OR
(kk_aj_tbl_utovare.Organisation LIKE '%'+@searchval+'%')AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll1) OR
(kk_aj_tbl_utovare.Organisation LIKE '%'+@searchval+'%')AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll2) OR
(kk_aj_tbl_utovare.Organisation LIKE '%'+@searchval+'%')AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll3) OR
(kk_aj_tbl_utovare.Organisation LIKE '%'+@searchval+'%')AND (kk_aj_tbl_Konstformtyp.KonstformID = @roll4)
)
ORDER BY kk_aj_tbl_arridtoContent.datum DESC
感谢所有帮助
答案 0 :(得分:3)
像这样的条件:
$ENV{PERL5DB}
可以改写为:
function updateForm(){
// call your form and connect to the drop-down item
var form = FormApp.openById("Your Form ID");
var namesList = form.getItemById("The Drop-Down List ID").asListItem();
// identify the sheet where the data resides needed to populate the drop-down
var ss = SpreadsheetApp.getActive();
var names = ss.getSheetByName("Name of Sheet in Spreadsheet");
// grab the values in the first column of the sheet - use 2 to skip header row
var namesValues = names.getRange(2, 1, names.getMaxRows() - 1).getValues();
var studentNames = [];
// convert the array ignoring empty cells
for(var i = 0; i < namesValues.length; i++)
if(namesValues[i][0] != "")
studentNames[i] = namesValues[i][0];
// populate the drop-down with the array data
namesList.setChoiceValues(studentNames);
}
因此,请尝试以下(cond1 OR cond2)
AND (cond1 OR cond3)
AND (cond1 OR cond4)
...
子句:
cond1 AND (cond2 OR cond3 OR cond4)
答案 1 :(得分:2)
首先使用自定义表格别名,这样您就不必重复完整的表格名称(使用有效的名称,而不是像我的示例那样使用A,B,C)。您可以将多个OR
重写为IN
:
WHERE
A.ArrangemangStatusID = @arrStatusTyp AND
D.Version = 1 AND
(
(B.Rubrik LIKE '%' + @searchval + '%' AND E.KonstformID IN (@roll1, @roll2, @roll3, @roll4)) OR
(B.Underrubrik LIKE '%' + @searchval + '%' AND E.KonstformID IN (@roll1, @roll2, @roll3, @roll4)) OR
(C.Organisation LIKE '%' + @searchval + '%' AND E.KonstformID IN (@roll1, @roll2, @roll3, @roll4))
)
您无需将所有条件括在括号中,仅在必要时使用它们。
答案 2 :(得分:0)
version: '3'
services:
mongodb:
image: mongodb:4
volumes:
- './mongodb:/data/db'
app:
build: .
ports: '3000:3000'
env:
MONGODB_HOST: mongodb
答案 3 :(得分:0)
使用表别名并简化WHERE子句:
SELECT am.ArrID
FROM kk_aj_tbl_content c
INNER JOIN kk_aj_tbl_arridtoContent a2c ON c.Contentid = a2c.contentid
INNER JOIN kk_aj_tbl_Arrangemang am ON a2c.arrid = am.ArrID
INNER JOIN kk_aj_tbl_ArrangemangStatus ams ON am.ArrangemangStatusID = ams.ArrangemangStatusID
INNER JOIN kk_aj_tbl_Konstformtyp kft ON am.KonstformID = kft.KonstformID
INNER JOIN Users u ON am.AdminuserID = u.UserID
INNER JOIN kk_aj_tbl_utovare uto ON am.UtovarID = uto.UtovarID
WHERE am.ArrangemangStatusID = @arrStatusTyp
AND a2c.Version = 1
AND kft.KonstformID in (@roll1,@roll2,@roll3,@roll4)
AND (
c.Rubrik LIKE '%'+@searchval+'%' OR
c.Underrubrik LIKE '%'+@searchval+'%' OR
uto.Organisation LIKE '%'+@searchval+'%'
)
ORDER BY a2c.datum DESC