Execute Stored Procedure from a Function

EDIT: I haven’t tried this, so I can’t vouch for it! And you already know you shouldn’t be doing this, so please don’t do it. BUT… Try looking here: http://sqlblog.com/blogs/denis_gobo/archive/2008/05/08/6703.aspx The key bit is this bit which I have attempted to tweak for your purposes: DECLARE @SQL varchar(500) SELECT @SQL = ‘osql -S’ +@@servername +’ … Read more

Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation ‘=’

The default collation for stored procedure parameters is utf8_general_ci and you can’t mix collations, so you have four options: Option 1: add COLLATE to your input variable: SET @rUsername = ‘aname’ COLLATE utf8_unicode_ci; — COLLATE added CALL updateProductUsers(@rUsername, @rProductID, @rPerm); Option 2: add COLLATE to the WHERE clause: CREATE PROCEDURE updateProductUsers( IN rUsername VARCHAR(24), IN … Read more

Are Stored Procedures more efficient, in general, than inline statements on modern RDBMS’s? [duplicate]

NOTE that this is a general look at stored procedures not regulated to a specific DBMS. Some DBMS (and even, different versions of the same DBMS!) may operate contrary to this, so you’ll want to double-check with your target DBMS before assuming all of this still holds. I’ve been a Sybase ASE, MySQL, and SQL … Read more

SQL Server sp_msforeachtable usage to select only those tables which meet some condition

You know how sp_MSforeachtable is undocumented, and may go away at any time/be modified? Well, if you’re happy to ignore that, it has another parameter called @whereand, which is appended to the WHERE clause of the internal query that is being used to find the tables (and should start with an AND). You also have … Read more