DECLARE @step VARCHAR(25) = '15';
DECLARE @COL VARCHAR(50) = step_col_@step;
UPDATE table_tblName SET @COL=<some value> WHERE <condition>
我有上述查询,其中@COL应该是动态的,即step_col_1,step_col_2,step_col_3 ...... step_col_18。如果没有在sql server中使用If-else条件,我该如何实现呢?
答案 0 :(得分:1)
尝试以下查询,
body {
border: 1px solid;
padding: 0 auto;
}
header {
height: 25%;
border-bottom: 1px solid;
}
header #logo {
float: left;
text-align: center;
width: 25%;
}
header #titre {
background: black;
color: white;
float: right;
text-align: center;
width: 75%;
}
#xd {}
nav {
width: 25%;
text-align: center;
float: left;
}
section {
width: 75%;
float: right;
text-align: center;
}
.clr {
clear: both;
}
答案 1 :(得分:0)
传递这样的变量以形成动态sql查询
DECLARE @step VARCHAR(25) = '15';
DECLARE @COL VARCHAR(50) = 'step_col_'+@step
exec ('UPDATE table_tblName SET '+@COL+'=<some value> WHERE <condition>')
答案 2 :(得分:0)
DECLARE @step VARCHAR(25) = '15';
DECLARE @COL VARCHAR(50) = 'step_col_'+@step;
DECLARE @String VARCHAR(500) = ''
SET @String = 'UPDATE table_tblName SET '''+@COL+''' = <some value> WHERE
<condition>'
EXEC (@String)
答案 3 :(得分:0)
DECLARE @step VARCHAR(25) = '15';
DECLARE @COL VARCHAR(50)
SET @COL = 'step_col'+@step;
UPDATE table_tblName SET @COL=<some value> WHERE <condition>