Mapping dynamic column names in sql server
问题 DECLARE @step VARCHAR(25) = '15'; DECLARE @COL VARCHAR(50) = step_col_@step; UPDATE table_tblName SET @COL=<some value> WHERE <condition> I have the above query where @COL is supposed to be dynamic i.e. step_col_1,step_col_2,step_col_3......step_col_18. How can I achieve this without If-else condition in sql server? 回答1: Try the below query, DECLARE @COL VARCHAR(50) = 'step_col_'+@step 回答2: Pass the variables like this to form a dynamic sql query DECLARE @step VARCHAR(25) = '15'; DECLARE @COL