我有一个问题是使用存储过程生成水晶报告。
这不起作用:
CREATE PROCEDURE [dbo].[GetPEBalDeliveryAssn]
@Assn VARCHAR(50),
@cropseason INT
IF @Assn = 'ALL'
BEGIN
SELECT
dbo.vDelFarReapGrpCodeBsiCode.farmer_pay_bsi,
dbo.vDelFarReapGrpCodeBsiCode.reaping_code,
dbo.vDelFarReapGrpCodeBsiCode.farmer_pay_name,
dbo.vDelFarReapGrpCodeBsiCode.delivered,
dbo.vDelFarReapGrpCodeBsiCode.number_deliveries,
dbo.FarmerGroups.PROD_EST,
dbo.vDelFarReapGrpCodeBsiCode.CropSeasonsID
FROM
dbo.FarmerGroups
INNER JOIN
dbo.vDelFarReapGrpCodeBsiCode ON dbo.FarmerGroups.BSI_CODE = dbo.vDelFarReapGrpCodeBsiCode.farmer_pay_bsi
WHERE
dbo.FarmerGroups.CROP_SEASON = @cropseason
AND dbo.vDelFarReapGrpCodeBsiCode.CropSeasonsID = @cropseason
ORDER BY
dbo.vDelFarReapGrpCodeBsiCode.reaping_code
END
但这样做
CREATE PROCEDURE [dbo].[GetPEBalDeliveryAssn]
@Assn VARCHAR(50),
@cropseason INT
IF @Assn = 'ALL' AND @cropseason = 1
BEGIN
SELECT
dbo.vDelFarReapGrpCodeBsiCode.farmer_pay_bsi,
dbo.vDelFarReapGrpCodeBsiCode.reaping_code,
dbo.vDelFarReapGrpCodeBsiCode.farmer_pay_name,
dbo.vDelFarReapGrpCodeBsiCode.delivered,
dbo.vDelFarReapGrpCodeBsiCode.number_deliveries,
dbo.FarmerGroups.PROD_EST,
dbo.vDelFarReapGrpCodeBsiCode.CropSeasonsID
FROM
dbo.FarmerGroups
INNER JOIN
dbo.vDelFarReapGrpCodeBsiCode ON dbo.FarmerGroups.BSI_CODE = dbo.vDelFarReapGrpCodeBsiCode.farmer_pay_bsi
WHERE
dbo.FarmerGroups.CROP_SEASON = 1
AND dbo.vDelFarReapGrpCodeBsiCode.CropSeasonsID = 1
ORDER BY
dbo.vDelFarReapGrpCodeBsiCode.reaping_code
END
我不确定为什么让@cropseason
无效并且有一个实际的1。
SET @cropseason = isnull(@cropseason,0)