From the course: Complete Guide to Advanced SQL Server

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Use variables in Python

Use variables in Python

Every Python script that you run in SQL Server is going to start the same way. You'll start up a new query window, and you're going to execute a stored procedure called sp_execute_external_script. This stored procedure has two required arguments. One is called @language and the other is @script. The language argument will always be set to equals Python. Remember that this is a Unicode text value, so include the capital letter N prefix and wrap the text in single quotation marks. Also, be sure to include the comma at the end to separate these two arguments. The script argument also gets specified as Unicode text with the N prefix. Then any Python code that you want to execute will be placed inside of a pair of single quotation marks. So this is going to be the starting point for every script that we write moving forward. The only thing that we need to worry about is what's between these two single quotation marks starting on Line Number 4. Using the print function, we can have…

Contents