简体   繁体   中英

Conditional column choosing sql server stored procedure

I have a stored procedure that receives many parameterIds and I want to choose a value from another table columns according to the parameterIds inputted. So the tables look like this.

Parameters table

ParameterID 
33
34
35

Values Table

InstallID       33Value      34Value   35Value

How can I retrieve the values according to the parameters inputted?

SELECT CASE
         WHEN @ParameterID = 33 THEN (SELECT 33Value
                                      FROM   [Values Table])
         WHEN @ParameterID = 34 THEN (SELECT 34Value
                                      FROM   [Values Table])
         ELSE (SELECT 35Value
               FROM   [Values Table])
       END 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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