如何使用存储过程从表中读取垂直列名称 [英] How to read the perticular Column name from table using store procedure

查看:48
本文介绍了如何使用存储过程从表中读取垂直列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DoctorsAvailability		
DoctorsId	int	Primary Key
NonAvailability	nvarchar(100)	not null
Mon	nvarchar(100)	not null
Tue	nvarchar(100)	not null
Wed	nvarchar(100)	not null
Thur	nvarchar(100)	not null
Fri	nvarchar(100)	not null
Sat	nvarchar(100)	not null
Sun	nvarchar(100)	not null


上面的是我的表,现在我想使用存储过程读取特定的列名,例如MonTue或网络等.在我的表中,当我通过时,我在日列中插入了一些数据像 Mon 这样的参数,我需要获取 Mon 列中存在的数据


The above one is my table, now i want to read the particular column name like Mon or Tue or web etc... using stored procedure and in my table I am having some data inserted in day columns, when I pass the parameter like Mon i need to get the data present in the Mon column

推荐答案

尝试以下...

try the following...

CREATE PROCEDURE GetMyData @Day int
AS
SELECT @Day FROM DoctorsAvailability 
GO



您需要在星期一5到星期四等通过4....

我不确定这种逻辑,我无法测试它,因为我这里没有sql server ...


问候
塞巴斯蒂安



You need to pass 4 for Monday 5 for tuesday etc....

I am not sure of this logic, and i am unable to test it as i don''t have sql server here...


Regards
Sebastian


尝试一下

try this

CREATE PROCEDURE GetMyData @Day int
AS

DECLARE @SQL NVARCHAR(MAX)

SET @SQL=' 
SELECT '+@Day+' FROM DoctorsAvailability
'

EXEC(@SQL)

GO


这篇关于如何使用存储过程从表中读取垂直列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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