在sql server中执行python脚本

时间:2018-02-27 10:20:57

标签: python sql-server

专家,

只是好奇才知道。有没有办法在任何sql server中执行python脚本?

若是,请提供一些参考链接

2 个答案:

答案 0 :(得分:0)

在sql server中执行python脚本引用此question

有关详细信息,请阅读此doc

我希望这会对你有所帮助! :)

答案 1 :(得分:0)

我离专家很远,但最近看起来这个,所以这里有一个非常简单的T-SQL脚本,如果它可以帮助任何人,可以使用嵌入式Python(注意:假设您在SQL Server上设置了Machine Learning Services with Python

-- Stored proc which runs embedded Machine Learning Services scripts
EXEC sp_execute_external_script

-- The SQL query to be input to the Python script
@input_data_1 = N'SELECT TOP(100) [CustomerID], [JobNumber] 
                  FROM [dbo].[Heading] ORDER BY DateDelivery DESC',

-- Variable name for the input SQL data ('InputDataSet' is the default if none)
@input_data_1_name = N'InputDataSet',

-- The language of the script
@language = N'Python',

-- Python script itself - Just imports Pandas and creates a new DataFrame with only one of the two input columns
@script = N'
import pandas as pd
OutputDataSet = pd.DataFrame(InputDataSet["CustomerID"])
'

-- Declaring SQL columns for the output (a Pandas DataFrame)
WITH RESULT SETS (
    ("CustomerID" INT NULL)
)