Storing query results into a variable and modifying it inside a Stored Procedure

Yup, this is possible of course. Here are several examples. — one way to do this DECLARE @Cnt int SELECT @Cnt = COUNT(SomeColumn) FROM TableName GROUP BY SomeColumn — another way to do the same thing DECLARE @StreetName nvarchar(100) SET @StreetName = (SELECT Street_Name from Streets where Street_ID = 123) — Assign values to several … Read more

How can I get the list of tables in the stored procedure?

The two highest voted answers use a lot of deprecated tables that should be avoided. Here’s a much cleaner way to do it. Get all the tables on which a stored procedure depends: SELECT DISTINCT p.name AS proc_name, t.name AS table_name FROM sys.sql_dependencies d INNER JOIN sys.procedures p ON p.object_id = d.object_id INNER JOIN sys.tables … Read more

MySQL procedure vs function, which would I use when?

The most general difference between procedures and functions is that they are invoked differently and for different purposes: A procedure does not return a value. Instead, it is invoked with a CALL statement to perform an operation such as modifying a table or processing retrieved records. A function is invoked within an expression and returns … Read more