如何从Sql Server中的特定列和行获取值? [英] How Can I Get Value From Specific Column And Row In Sql Server?

查看:96
本文介绍了如何从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..


这篇关于如何从Sql Server中的特定列和行获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆