Search notes:

SQL Server: execute

execute executes
execute can be abbreviated with exec.
In SQL batches, execute is not required to execute a stored procedure if it is the first statement in the batch.

Execute a character string

execute (string) executes the value of a string is executed as (or in) a batch.
Note: the parentheses are required.
declare
   @db_name     varchar(20) = db_name(),
   @table_name  varchar(20) = 'a_table';

   execute (
      ' use ' + @db_name +
      ' create table ' + @table_name + '(id integer)'
   )

Execute a stored procedure

When executing a stored procedure, the parameters must not be enclosed in parentheses. In fact, there are no parentheses allowed because with parentheses, SQL Server tries to execute a character string.
create procedure greet_planet (
   @planet varchar(20) = 'world'
)
as
   print('Hello ' + @planet);
go

execute greet_planet
execute greet_planet 'Mars'
execute greet_planet @planet = 'Jupiter'

--
-- Cannot use paranthesis when execute stored procedure:
--
-- execute greet_planet(@planet = 'Saturn')

drop procedure greet_planet;
Github repository about-MSSQL, path: /t-sql/statements/execute/stored-procedure-without-parantheses.sql

See also

The system stored procedure sp_executesql that allows to execute a dynamically created SQL statement with parameters.
T-SQL statements

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759331269, '216.73.216.88', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQL-Server/T-SQL/statements/execute/index(96): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78