The dynamic SQL query string can be executed using EXEC or EXECUTE command or using the sp_executesql stored procedure. You can also build and execute SQL query string by directly passing the SQL query string to sp_executesql stored procedure, as shown below. The above would return the same result.