Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query Not Working
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01406608
Message ID:
01406636
Views:
34
Kevin,

Try using the COALESCE(...) function instead because it can accept more than two parameters.
COALESCE(r.Status,'') = COALESCE(@Status,r.Status,'')
Hope this helps.
Kurt

>I guess I don't understand the difference because I have some queries that use ISNULL() and they work ok.
>
>>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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform