d90sg98a7sdg
d90sg98a7sdg

Reputation: 11

Why won't my SQL Server database show any results while running stored procedure?

Please look at the code I created. The first block is my stored procedure that I created.

The second block is me running the code manually, bypassing the stored procedure.

The 3rd block is me running the code using the stored procedure.

When I run the code without the stored procedure, I get results. When I run the code via the stored procedure, I don't get anything, even though it's presumably the same code.

ALTER PROCEDURE [dbo].[uspCheckSaleVIN] 
    @VIN nvarchar(17)
AS
    SELECT * 
    FROM Sales
    WHERE VIN = @VIN

    SELECT * 
    FROM Sales
    WHERE (VIN = 09872345098723457)
GO

uspCheckSaleVIN 09872345098723457

Upvotes: 1

Views: 104

Answers (1)

Giorgi Nakeuri
Giorgi Nakeuri

Reputation: 35780

Do it like:

uspCheckSaleVIN '09872345098723457'

This is because 09872345098723457 is numeric and leading zero is just truncated from literal. Of course it would work only if you have non zero leading digit.

Proof:

CREATE PROCEDURE test
@p VARCHAR(5)
AS

SELECT @p

GO


EXEC test 01234
EXEC test '01234'

Outputs:

1234
01234

Upvotes: 2

Related Questions