在SQL Server中映射动态列名称 [英] Mapping dynamic column names in sql server
本文介绍了在SQL Server中映射动态列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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条件的情况下实现此目标?
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?
推荐答案
尝试以下查询,
DECLARE @COL VARCHAR(50) = 'step_col_'+@step
这篇关于在SQL Server中映射动态列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文