Gouache painting of a wooden shape-sorter box with matching shapes in front and the round one painted red

How to Pass Parameters to a Stored Procedure in SQL Server

To pass parameters to a stored procedure, write the values after EXEC without parentheses, and name each parameter so the order can’t matter. This post builds a small order procedure and calls it by position and by name, with defaults, an OUTPUT value and a table-valued parameter. It also shows the three errors people hit first and what each one means.

Read More
A string passed to EXEC runs as a statement and returns 5 rows, while EXEC with a parameter fails with Msg 102 and sp_executesql with a parameter returns the 2 Smith rows

Run a String as SQL: EXEC, Parameters and Four Traps

To run a string as SQL, you pass it to EXEC or to sp_executesql, and SQL Server runs the text as a statement. This post builds a string from pieces, shows why EXEC cannot take parameters, and adds them with sp_executesql. It also shows four traps: a variable the string cannot see, a NULL that empties the string, a variable that is too short, and a function that cannot run a string. Every result comes from SQL Server 2025.

Read More