我在下面有以下存储过程。当我尝试使用此代码执行存储过程时;
exec [transport]。[dbo]。[Delivery_Manifest_email] @RunNo ='3'
我收到以下错误
Msg 8146,Level 16,State 2,Procedure Delivery_Manifest_email,Line 0
过程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 '+@runno + ', ' +@Driver +', ' +@lorry
SET @recip = 'test@test.co.uk'
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
答案 0 :(得分:3)
您没有为存储过程定义参数。您需要将它们定义为:
...
CREATE PROCEDURE [dbo].[Delivery_Manifest] (@RunNo NVARCHAR(MAX))
AS
...