BLOG

Explore our fascinating news.

Using Python for data science in SQL Server Reporting Services (SSRS) can indeed be a valuable approach, leveraging the power and versatility of Python within the SSRS environment. While SQL Server 2017 introduced support for R language, Python was not natively supported in SSRS at that time. However, with subsequent releases, Microsoft has expanded support for Python in SQL Server, including SQL Server Reporting Services.

Stored Procedures for Python Date Frames

The ‘sp_execute_external_script’ stored procedure allows us to pass data between SQL Server and Python using data frames. SQL Server can pass data to Python as a data frame, and Python can return results to SQL Server in the form of a data frame. This data frame-based communication simplifies the interaction between SQL Server and Python.

By leveraging the pandas library in Python, we can manipulate, analyze, and transform the data passed from SQL Server. Pandas provides powerful data manipulation and analysis capabilities, making it a popular choice for working with tabular data in Python.

Implementation Method

EXECUTE sp_execute_external_script
@language = N'Python',
@script = N'OutputDataSet = InputDataSet', -- Assign the input data set to the output data set
@input_data_1 = N'SELECT 1 AS result'
WITH RESULT SETS
(
(
result INT -- Define the structure of the result set with a single column named 'result'
)
)


The Above code executes a simple Python script using the 'sp_execute_external_script' stored procedure in SQL Server. The script assigns the input data set (InputDataSet) to the output data set (OutputDataSet), effectively copying the data. It then returns the result set containing a single column named result with a value of 1.

The WITH RESULT SETS clause is used to define the structure of the result set returned by the script. In this case, it specifies that the result set should have a single column named result of type INT.