1
以下のストアドプロシージャがあります。このコードでストアドプロシージャを実行しようとすると、パラメータ付きストアドプロシージャの実行SQL Server 2005
のexec [運輸]。[DBO]。[Delivery_Manifest_email] @RunNo = '3'
私は次のエラー
メッセージ8146を取得し、レベル16、状態2、手順Delivery_Manifest_email、ライン0
Procedure Delivery_Manifest_emailにはパラメータがなく、引数が指定されています。
私は@RunNo
パラメータを渡そうとしていますが、なぜ私の構文が間違っているのかわかりません。ストアドプロシージャ自体で@RunNo
パラメータを手動で設定すると、ストアドプロシージャが正常に実行されます。私はこのようにしたくない。 SQL Serverは2005です。
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Delivery_Manifest]
AS
DECLARE @tableHTML NVARCHAR(MAX);
DECLARE @HTMLBody NVARCHAR(MAX)
DECLARE @XML NVARCHAR(MAX)
DECLARE @s NVARCHAR(MAX)
DECLARE @Driver NVARCHAR(MAX)
DECLARE @Lorry NVARCHAR(MAX)
DECLARE @recip NVARCHAR(MAX)
DECLARE @varCheck BIT
DECLARE @DueDate VARCHAR(10)
DECLARE @RunNo NVARCHAR(MAX)
SET @DueDate = '27/06/2016'
SET @Driver = 'Test
SET @Lorry ='Test'
SET @s = 'Delivery Manifest for: ' +CONVERT(VARCHAR(12),GETDATE(),107) +', Run number '[email protected] + ', ' [email protected] +', ' [email protected]
SET @recip = '[email protected]'
IF EXISTS (SELECT [OrderNoOnManifest], [Lorry], [Driver], [Name], [Town], [POSTCODE], [Telephone], [DELIVERY NOTE], [Notes], [Shipping Weight (Kg)], [PackagingLength], [District], [ServiceLevel], [SpecificDelTime] FROM [Transport].[dbo].[DELIVERY_MANIFEST_MASTER] WHERE [Due Date] = @DueDate and [Run No] = @RunNo)
SET @tableHTML = '<style type="text/css">
table.tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #9dcc7a;border-collapse: collapse;}
table.tftable th {font-size:12px;color:#ffffff;background-color:#ff1a00;border-width: 1px;padding: 8px;border-style: solid;border-color: #9dcc7a;text-align:left;}
table.tftable tr {background-color:#ffffff;}
table.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #9dcc7a;}
</style>
<body>
'
+ @s +'<p style="text-align:left;"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;text-decoration:none;text-transform:none;color:000033;"> </span>
</p>
<br>
<table class="tftable" border="2">'
+ N'<th>Order</th>'
+ N'<th>Customer</th>'
+ N'<th>Town</th>'
+ N'<th>Postcode</th>'
+ N'<th>Tel. No.</th>'
+ N'<th>Order No</th>'
+ N'<th>Notes</th>'
+ N'<th>Weight (Kg)</th>'
+ N'<th>Dimension</th>'
+ N'<th>Instructions</th>'
+ N'<th>Service Level</th>'
+ N'<th>Delivery Time By</th></tr>'
+ CAST (( SELECT
td = [OrderNoOnManifest], ''
, td = [Name] , ''
, td = [Town], ''
, td = [POSTCODE] ,''
, td = [Telephone],''
, td = [DELIVERY NOTE],''
, td = [Notes],''
, td = [Shipping Weight (Kg)],''
, td = [PackagingLength],''
, td = isnull([District],'None'),''
, td = isnull([ServiceLevel],0),''
,td = isnull([SpecificDelTime],0),''
FROM [Transport].[dbo].[DELIVERY_MANIFEST_MASTER]
WHERE [Due Date] = @DueDate and [Run No] = @RunNo
ORDER BY [OrderNoOnManifest] asc
FOR
XML PATH('tr')
, TYPE
) AS NVARCHAR(MAX)) + N'</table>'
+'<br>'
+'<br>'
+ '<p style="text-align:left;"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:bold;text-decoration:none;text-transform:none;color:000033;">TEST DELIVERY MANIFEST EMAIL</span>
'
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@blind_copy_recipients = @recip,
@profile_name = 'Test',
@subject = @s,
@body = @tableHTML,
@body_format = 'HTML' ;
END
これは、ありがとう! – Andy