Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sp-executesql-transact-sql.md #9823

Open
wants to merge 2 commits into
base: live
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ EXEC sp_executesql @InsertString,
GO
```

Using `sp_executesql` in this procedure is more efficient than using `EXECUTE` to execute a string. When `sp_executesql` is used, there are only 12 versions of the `INSERT` string that are generated, one for each monthly table. With `EXECUTE`, each `INSERT` string is unique because the parameter values are different. Although both methods generate the same number of batches, the similarity of the `INSERT` strings generated by `sp_executesql` makes it more likely that the query optimizer reuses execution plans.
Using `sp_executesql` in this procedure is more efficient than using `EXECUTE` to execute a string. With `EXECUTE`, each `INSERT` string is unique because the parameter values are different. When `sp_executesql` is used, there is only one `INSERT` string generated for each language, month and year combination. (`DATENAME()` returns different values depending on the value of `LANGUAGE` in the session that is executing the `InsertSales` procedure.) Although both methods generate the same number of batches, the similarity of the `INSERT` strings generated by `sp_executesql` makes it more likely that the query optimizer reuses execution plans.

### C. Use the OUTPUT parameter

Expand Down