Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query Not Working
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01406608
Message ID:
01406610
Vues:
55
Kevin,

I think we discussed this at least 3 times already before. Try

(@Status IS NULL or Status = @Status)
SELECT	r.*, 
>			p.PartNo, 
>			p.Description,
>			u.FullName,
>			w.Caption AS Warehouse
>		FROM Returns r
>		JOIN Parts p ON p.PartId = r.PartId
>		JOIN Warehouses w ON w.WarehouseId = r.WarehouseId
>		JOIN Users u ON u.UserId = r.UserId
>		WHERE r.WarehouseId = @WarehouseId AND
>			  (@Status IS NULL OR r.Status = @Status)
>		ORDER BY p.PartNo, r.SerialNo DESC
>I'm trying to add in the @Status:
>
>Here's the data:
>
>
>ReturnId    WarehouseId SerialNo     Details       Status ActionDate
>----------- ----------- -----------  ------------- ------ -----------------------
>1           20          NULL         Details 1     NULL   2009-06-17 09:01:44.240
>2           20          NULL         Carlsbad      NULL   2009-06-17 09:08:10.533
>
>
>I want the add into my sproc the option to pass in a status code, or none:
>
>
>
>CREATE PROCEDURE ap_GetReturnsForWarehouse
>	@WarehouseId INT,
>	@Status		 TINYINT = NULL
>	
>AS
>BEGIN
>
>	SELECT	r.*, 
>			p.PartNo, 
>			p.Description,
>			u.FullName,
>			w.Caption AS Warehouse
>		FROM Returns r
>		JOIN Parts p ON p.PartId = r.PartId
>		JOIN Warehouses w ON w.WarehouseId = r.WarehouseId
>		JOIN Users u ON u.UserId = r.UserId
>		WHERE r.WarehouseId = @WarehouseId AND
>			  r.Status = ISNULL(@Status, r.Status)
>		ORDER BY p.PartNo, r.SerialNo DESC
>
>END
>
>
>
>I'm calling it like this:
>
>
>exec ap_GetReturnsForWarehouse @WarehouseId = 20, @Status = NULL
>
>
>I'm getting no data back.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform