Use parameter as column name in table-valued function in SQL Server

时间:2016-08-31 17:39:03

标签: sql-server

ALTER FUNCTION [dbo].[cycleplan_doctor_view] 
    (@Parameter1 INTEGER, @Group VARCHAR(MAX))
RETURNS TABLE
AS
    RETURN
        (SELECT * 
         FROM tbl_master_doctor 
         WHERE int_doctor_id IN (SELECT int_doctor_id 
                                 FROM tbl_master_MR 
                                 WHERE int_user_id = @Parameter1 
                                   AND @Group = 'Yes')
        )

When I am passing a value for @Group, I am getting empty table. But when I replace the value of @Group with its value it is working correctly.

I think I am missing some basic thing here.

0 个答案:

没有答案