Temporary function or stored procedure in T-SQL

This question is a bit old, but the other answers failed to provide the syntax for creating temporary procedures. The syntax is the same as for temporary tables: #name for local temporary objects, ##name for global temporary objects. CREATE PROCEDURE #uspMyTempProcedure AS BEGIN print ‘This is a temporary procedure’ END This is described in the … Read more

mysql stored-procedure: out parameter

Unable to replicate. It worked fine for me: mysql> CALL my_sqrt(4, @out_value); Query OK, 0 rows affected (0.00 sec) mysql> SELECT @out_value; +————+ | @out_value | +————+ | 2 | +————+ 1 row in set (0.00 sec) Perhaps you should paste the entire error message instead of summarizing it.

Difference between Parameters.Add(string, object) and Parameters.AddWithValue

There is no difference in terms of functionality. In fact, both do this: return this.Add(new SqlParameter(parameterName, value)); The reason they deprecated the old one in favor of AddWithValue is to add additional clarity, as well as because the second parameter is object, which makes it not immediately obvious to some people which overload of Add … Read more

Inserting into Oracle and retrieving the generated sequence ID

Expanding a bit on the answers from @Guru and @Ronnis, you can hide the sequence and make it look more like an auto-increment using a trigger, and have a procedure that does the insert for you and returns the generated ID as an out parameter. create table batch(batchid number, batchname varchar2(30), batchtype char(1), source char(1), … Read more

Query runs fast, but runs slow in stored procedure

OK, we have had similar issues like this before. The way we fixed this, was by making local parameters inside the SP, such that DECLARE @LOCAL_Contract_ID int, @LOCAL_dt_From smalldatetime, @LOCAL_dt_To smalldatetime, @LOCAL_Last_Run_Date datetime SELECT @LOCAL_Contract_ID = @Contract_ID, @LOCAL_dt_From = @dt_From, @LOCAL_dt_To = @dt_To, @LOCAL_Last_Run_Date = @Last_Run_Date We then use the local parameters inside the SP … Read more