简体   繁体   English

如何编写存储过程以使用功能选择特定列

[英]how to write stored procedure to select a particular column using functions

I have two tables 我有两张桌子

tblSTATUS
   StatusID|PlanID|Description|EmailSubject|EmailFrom|EmailTo||Comment
     1        8    Approved                                aaa
     2        7    Rejected                                bbb
     3        7    Rejected                                ccc
     4        42   Rejected                                ccc

tblSTATUSREASON
     PlanID|REASONS 
       7      failed
       7      not eligible
       42     not eligible

when i send email to particular person if their plan is (only) rejected it stores in table tblstatusreason the reasons for rejected and PlanID used which is dependent on tblStatus . 当我向某人发送电子邮件(如果他们的计划(仅)被拒绝)时,它会将拒绝的原因和使用的tblstatusreason存储在表tblstatusreason ,这取决于tblStatus

i should retrieve evrything in grid view C# code using stored procedures and displaying it for user according to description. 我应该使用存储过程在网格视图C#代码中检索evrything,并根据说明将其显示给用户。

Now my problem is i can retrieve and display all the other columns but i dont know how to display rReasons so i want to select [REASONS] from tblSTATUSREASON where for that particluar description = rejected from tblSTATUS and also i dont want to change my tables/columns.I need sql stored procedure for this particular thing 现在我的问题是我可以检索并显示所有其他列,但是我不知道如何显示rReasons,因此我想select [REASONS] from tblSTATUSREASONselect [REASONS] from tblSTATUSREASON其中的select [REASONS] from tblSTATUSREASON description = rejected from tblSTATUS我也不想更改表/列。我需要针对此特定事物的sql存储过程

You need also where 您还需要在哪里

select R.PlanID,REASONS
FROM tblSTATUSREASON R
INNER JOIN tblSTATUS S
ON R.PlanID = S.PlanID
AND description = 'rejected' 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM