call sql from a user defined function

早过忘川 提交于 2020-01-04 08:16:08

问题


Is it possible with SQL Server 2008 to execute sql from a variabele in a user defined function? Or is using a stored procedure the only solution?

I have an sql statement saved in a variabele

@mySqlStatement = "select * from someTable"

I want to execute the above statement from within a user defined function, is that possible?


回答1:


Yes it is possible, with restrictions. Please read this.

Also, be very careful about queries you write that are to be executed in a UDF. Query optimization can be a real problem and so can the number of times queries get executed, depending on how the UDF is called.




回答2:


Do you mean is it possible to run SQL from an external programming language? Of course it is.




回答3:


For sure yes! You can execute SQL code without using a stored procedure.. (if this is the question..)



来源:https://stackoverflow.com/questions/4585502/call-sql-from-a-user-defined-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!