gpt4 book ai didi

sql - 将参数从Powershell传递到存储过程

转载 作者:行者123 更新时间:2023-12-03 00:26:50 27 4
gpt4 key购买 nike

我试图使用Powershell将2个参数传递给存储过程。

我的代码如下,当我在Powershell中运行它时,没有错误。但是,似乎没有传递参数,因为我无法获得正确的结果。下面有什么问题吗?

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=localhost;Database=AMSDataWarehouse Test;Integrated Security=SSPI"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.Connection = $SqlConnection
$sqlcmd.CommandText = "YQBReport1"
$param1=$sqlcmd.Parameters.Add("@from" , [System.Data.SqlDbType]::DateTime)
$param1.Value = "2013-03-13"
$param2=$sqlcmd.Parameters.Add("@to" , [System.Data.SqlDbType]::DateTime)
$param2.Value = "2013-03-14"
$SqlConnection.Open()
$sqlcmd.ExecuteNonQuery()
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$SQLResult =$DataSet.Tables[0]
$commands = $SQLResult | foreach-object -process { $_.output }> output.ps1
.\output.ps1

添加代码YQBReport1
create PROCEDURE YQBreport1 
AS
declare @from datetime, @to datetime, @TypeBigAC char(3)
select @TypeBigAC='333'

Select
'$application = New-Object -ComObject Visio.Application;
$documents = $application.Documents;
$document = $documents.Add("AMSGantt.vst");
$pages = $application.ActiveDocument.Pages;
$page = $pages.Item(1);
$shape500 = $page.DrawLine(2,7.9,11,7.9);
$shape500.TextStyle = "Title";
$shape500.LineStyle = "Title";'
as output
union all

select
'$shape500.text = '+'"'+'Assignation de Barrières-' + DATENAME(WEEKDAY,@from)+','+DATENAME(MONTH,@from)+' '+DATENAME(DAY,@from)+','+DATENAME(YEAR,@from)+'"'+';'
as output
Union all

SELECT
'$shape'+cast(ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+' = $page.DrawRectangle'+'('+CAST(X1 as varchar)+','+CAST(Y1 as varchar)+','+CAST(X2 as varchar)+','+CAST(Y2 as varchar)+')'+';'
+'$shape'+ cast(ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.'+'LineStyle = Gantt"'+';'
+'$shape'+ cast(ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.'+'TextStyle = "Gantt"'+case when left(arrival, 2)='AC' THEN 'Red' ELSE '' END+ CASE WHEN LEFT(Departure, 2)='AC' THEN 'Red' ELSE '' END+';'
+'$shape'+ cast(ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.FillStyle = "Gantt'+CASE WHEN CHARINDEX(@TypeBigAC, [ACType Iata])<>0 THEN ' Big AC' ELSE '' END+'"'+';'
+'$shape'+ cast(ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.Text = "'+case when LEN(arrival)<>0 THEN Arrival ELSE '###' END +' / '+ case when len([ACType Iata])<>0 then [ACType Iata] else ' ' end +' / '+ CASE WHEN LEN(Departure)<>0 THEN Departure ELSE '###' END +'"'+';'
+'$shape'+ cast(100+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+' = $page.DrawLine('+cast(X1 -0.5 as varchar)+','+cast(Y1 -0.03 as varchar)+','+cast(X1 +0.5 as varchar)+','+cast(Y1 -0.03 as varchar)+ ')'+';'
+'$shape'+ cast(100+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.Text = "'+CONVERT(char(5), [Allocation Start Datetime], 108)+'"'+';'
+'$shape'+ cast(100+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.TextStyle = "Times"'+';'
+'$shape'+ cast(100+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.LineStyle = "Times"'+';'
+'$shape'+ cast(200+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+' = $page.DrawLine('+cast(X2 -0.1 as varchar)+','+cast(Y1 -0.03 as varchar)+','+cast(X2 +0.1 as varchar)+','+cast(Y1 -0.03 as varchar)+ ')'+';'
+'$shape'+ cast(200+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.Text = "'+CONVERT(char(5), [Allocation End Datetime], 108)+'"'+';'
+'$shape'+ cast(200+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.TextStyle = "Times"'+';'
+'$shape'+ cast(200+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.LineStyle = "Times"'+';'


as output
FROM GanttReport(@from,@to,@TypeBigAC)
union all
select '$shape'+ cast(300+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+' = $page.DrawLine('+cast(X1 as varchar)+','+cast(Y2 as varchar)+','+cast(X2 as varchar)+','+cast(Y1 as varchar)+ ')'
from GanttReportTowingLines(@from,@to,@TypeBigAC)

最佳答案

试试这个

$commands = $SQLResult | foreach-object -process { $_.output }>> output.ps1

关于sql - 将参数从Powershell传递到存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15340496/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com