如何从Sql Server中的特定列和行获取值?

问题描述:

大家好,



我的数据如下:

Hi all,

I have data like the below:

Code     Jan     Feb     Mar     Apr     May     Jul .... Dec
1        10       20      30     40      50       60       90
2        1        2       3      4        5        6        9
3        2        4       5      7        5        4        6



我有1个参数@Month nvarchar(10)

如果@ Month ='Jan'且Code = 1 ===>它将显示10

如果@ Month ='Apr'且Code = 2 ===>它将显示4

如果@ Month ='Dec'且Code = 1 ===>它将显示90







@Month将动态基于用户选择一个月。



有可能吗?



谢谢



TONY


I have 1 paramter @Month nvarchar(10)
If @Month='Jan' and Code=1 ===> it will display 10
If @Month='Apr' and Code=2 ===> it will display 4
If @Month='Dec' and Code=1 ===> it will display 90
.
.
.
The @Month will be dynamic base on the user choose month.

Is it possible to do that?

Thanks

TONY

你需要两个动态参数,一个在select中,一个在where子句中。



如需参考,请参阅:使用动态SQL存储过程 [ ^ ]



问候..
You need two dynamic parameters, one in select and one in where clause of the query.

For reference,see this : Using Dynamic SQL in Stored Procedures[^]

Regards..