How to PRINT a message from SQL CLR function?

The answer is that you cannot do the equivalent of PRINT ‘Hello World’ from inside a [SqlFunction()]. You can do it however from a [SqlProcedure()] using SqlContext.Pipe.Send(“hello world”) This is consistent with T-SQL, where you would get the error “Invalid use of a side-effecting operator ‘PRINT’ within a function” if you stick a PRINT inside … Read more

SQL Server stops loading assembly

Assemblies with EXTERNAL_ACCESS are, through some convoluted path, falling under the EXECUTE AS path. The problem appears when the ‘dbo’ cannot be mapped to a valid login. dbo’s login is the login with the SID the owner_sid value in sys.databases. Unless an AUTHORIZATION clause was used in CREATE DATABASE the owner_sid is the login sid … Read more

Difference between scalar, table-valued, and aggregate functions in SQL server?

Scalar Functions Scalar functions (sometimes referred to as User-Defined Functions / UDFs) return a single value as a return value, not as a result set, and can be used in most places within a query or SET statement, except for the FROM clause (and maybe other places?). Also, scalar functions can be called via EXEC, … Read more