Hi I have a large T-SQL proc which normaly retrieves a recordset from the DB which i then display the results within my Application. I wish to output @TotalWeight (even if i get no results within the main recordset).
How do i do this?
-Gus
How do i do this?
Code:
CREATE PROCEDURE [dbo].[usp_ShippingOptionsGet]
@CustomerID int,
AS
DECLARE @ShippingZoneID int,
@ShippingCode Char(2)
@TotalWeight int
SELECT @ShippingZoneID = Countries.ShippingZoneID
FROM Customer JOIN Address ON Customer.BillingAddressID = Address.AddressID
JOIN Countries ON Address.CountryCode = Countries.Country_Code WHERE Customer.CustomerID = @CustomerID
SELECT @TotalWeight = Sum([O].Weight*[B][I].Quantity) FROM [BasketItem] AS [B][I]
JOIN tblOptions AS [O] ON [B][I].OptionID = [O].Option_ID
WHERE ([B][I].CustomerID = @CustomerID)
SELECT @ShippingCode = ShippingCode FROM Shipping
WHERE ShippingZoneID = @ShippingZoneID
AND WeightRangeLow <= @TotalWeight AND WeightRangeHigh > @TotalWeight
SELECT
*
FROM
Shipping AS [ShipNormal]
JOIN
ShippingZone AS [SZ]
ON
[ShipNormal].ShippingZoneID = [SZ].ShippingZoneID
WHERE
[SZ].ShippingZoneID = @ShippingZoneID
AND
[ShipNormal].WeightRangeLow <= @TotalWeight
AND
[ShipNormal].WeightRangeHigh > @TotalWeight
UNION
SELECT
*
FROM
Shipping AS [ShipUnusal]
JOIN
ShippingZone AS [SZ]
ON
[ShipUnusal].ShippingZoneID = [SZ].ShippingZoneID
WHERE
[SZ].ShippingZoneID = @ShippingZoneID
AND
[ShipUnusal].WeightRangeLow is Null
AND
[ShipUnusal].WeightRangeHigh is Null
AND
[ShipUnusal].ShippingCode > @ShippingCode
ORDER BY
ShippingCode
-Gus