SQL Server, T-SQL, ASP.NET, Javascript, SAP, ABAP Programming

Kodyaz Development Resources

Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.
Welcome to Kodyaz Development Resources Sign in | Join | Help




SQL Server EXEC or SP_EXECUTESQL Commands in User Defined Functions


I developed a user-defined function named ReplaceTextColumn. I build the udf function and coded t-sql statements in order to build dynamic t-sql codes. I tried to use this dynamic sql codes to replace text or ntext sql data type columns in sql databases.

I tried to execute the resultant t-sql code block by calling the EXEC sp_executesql syntax but get the following SQL Server error message, Msg 443

Msg 443, Level 16, State 14, Procedure ReplaceTextColumn, Line 20
Invalid use of a side-effecting operator 'INSERT EXEC' within a function.
Invalid use of a side-effecting operator 'EXECUTE STRING' within a function.




Also calling the user defined function in a select statement resultant with sql engine raise the following error message Msg 557

select dbo.ReplaceTextColumn('','','','','','')
--Msg 557, Level 16, State 2, Line 1
--Only functions and some extended stored procedures can be executed from within a function.

So I changed the structure to use stored procedure instead of using user defined functions (udf) because of the limitations of user functions in SQL Server.






Related SQL Resources

SQL Server Articles

SQL Server Tools

SQL Blog

SQL Server 2008 Blog

Certification Exams Blog

Reporting Services Blog

Analysis Services Blog

MS SQL Server Forums



Free Exam Vouchers












Copyright © 2004 - 2010 Eralper Yilmaz. All rights reserved.
Powered by Community Server, by Telligent Systems