Can we pass parameters to a view in SQL?

前端 未结 20 2120
庸人自扰
庸人自扰 2020-11-29 18:29

Can we pass a parameter to a view in Microsoft SQL Server?

I tried to create view in the following way, but it doesn\'t work:

create o         


        
相关标签:
20条回答
  • 2020-11-29 18:59

    no. if you must then use a user defined function to which you can pass parameters into.

    0 讨论(0)
  • 2020-11-29 18:59

    I have an idea that I haven't tried yet. You can do:

    CREATE VIEW updated_customers AS
    SELECT * FROM customer as aa
    LEFT JOIN customer_rec as bb
    ON aa.id = bb.customer_id
    WHERE aa.updated_at between (SELECT start_date FROM config WHERE active = 1) 
    and (SELECT end_date FROM config WHERE active = 1)
    

    Your parameters will be saved and changed in the Config table.

    0 讨论(0)
提交回复
热议问题