如何在我的示例中将参数作为列名传递给存储过程

时间:2017-04-24 21:01:42

标签: sql sql-server

CREATE PROCEDURE ProcedureName1 
    @columnsname varchar(50), 
    @columnsvalue varchar(50) 
AS 
BEGIN 
    with cet as   
    ( 
        Select  ID,
                names,
                Null As address,
                work,
                note
        From    Tabl1
        Where   @columnsname Like @columnsvalue
        Union All
        Select  t2.ID,
                t2.name,
                t2.address,
                Null,
                Null As tt
        From    Tabl2 As t2
        Left Join Tabl1 As t1
                On t2.ID = t1.ID
        Where   @columnsname Like @columnsvalue 
    )  
    Select  *
    From    cet
    Order By id,
            note Desc,
            cet.address  
END GO

1 个答案:

答案 0 :(得分:0)

你必须使用动态sql这样的东西。将let myView = Bundle.main.loadNibNamed("MyViewWithLabels", owner: nil, options: nil)![0] as! MyViewWithLabels的价值列入var brush = new SolidColorBrush(Color.FromRgb(r,g,b));@columnsname的白名单也是一个好主意。

使用sys.columns继续保留information_schema.columns作为参数,而不是将其连接到您将要执行的SQL。

sp_executesql

参考: