Question : Select statement is trimming off the leading zero

I have a stored procedure that selects a couple values and then does some calculations and then returns.  When the first select (select @zone = @ServiceLevel from....) the @zone gets a value of 45.  When I do this select without putting it into a parameter, I get 045.  The value that @Zone is storing needs to be 045 not 45.

Any Ideas?  @Zone is a nvarchar(15) so I thought that this would keep the leading zero.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Brandon Leitheiser
-- Create date: 07.11.2010
-- Description:	This stored Procedure should be called when the system wants to find out the price of ups
--              hundred weight.
-- =============================================
CREATE PROCEDURE [dbo].[sp_CalcUPSHundredWeightGround]
	-- Add the parameters for the stored procedure here
	
	@Zip nvarchar(10),
	@TotalWeight int,
	@ServiceLevel nvarchar(10),
	@PlantID nvarchar(50),
	@Tier bit,
	@Zone nvarchar(15) = null,
	@UnitPrice money = null,
	@TotalPrice money output
	[email protected] money OUTPUT


AS
BEGIN
    
       
    select @Zone = @ServiceLevel from upshundredweightzipzone 
    where zipstart <= @Zip and zipEnd >= @Zip and PlantID = @PlantID and Tier = @Tier 
    IF @@RowCount > 0
		Begin
		Select @UnitPrice = Price from upshundredweightzoneprice
		where Zone = @Zone and "weight" >= @TotalWeight and PlantID = @PlantID and Tier = @Tier
		Select @TotalPrice = (@TotalWeight / 100) * @UnitPrice
		Return @TotalPrice
		End
	Else
		Begin
		Select @TotalPrice = 0.00
		return @TotalPrice
		End		
END

GO

Answer : Select statement is trimming off the leading zero

Try this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Brandon Leitheiser
-- Create date: 07.11.2010
-- Description:	This stored Procedure should be called when the system wants to find out the price of ups
--              hundred weight.
-- =============================================
CREATE PROCEDURE [dbo].[sp_CalcUPSHundredWeightGround]
	-- Add the parameters for the stored procedure here
	
	@Zip nvarchar(10),
	@TotalWeight int,
	@ServiceLevel nvarchar(10),
	@PlantID nvarchar(50),
	@Tier bit,
	@Zone nvarchar(15) = null,
	@UnitPrice money = null,
	@TotalPrice money output
	[email protected] money OUTPUT


AS
BEGIN
    
       
    select @Zone = CAST(@ServiceLevel AS VARCHAR(MAX)) from upshundredweightzipzone 
    where zipstart <= @Zip and zipEnd >= @Zip and PlantID = @PlantID and Tier = @Tier 
    IF @@RowCount > 0
		Begin
		Select @UnitPrice = Price from upshundredweightzoneprice
		where Zone = @Zone and "weight" >= @TotalWeight and PlantID = @PlantID and Tier = @Tier
		Select @TotalPrice = (@TotalWeight / 100) * @UnitPrice
		Return @TotalPrice
		End
	Else
		Begin
		Select @TotalPrice = 0.00
		return @TotalPrice
		End		
END

GO
Random Solutions  
 
programming4us programming4us