Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Query locks up

$
0
0

I'm aware that this query is horrible practice using the like statements, but due to variables that are out of my control I have to do it this way. I don't want to have a discussion about why I'm doing this. I just want to know why it is behaving this way. I have the following query:

DECLARE @PO nvarchar(4000)
DECLARE @VENDOR nvarchar(4000)
DECLARE @PARTNUMBER nvarchar(4000)
DECLARE @SHIPDATESTARTDATE nvarchar(4000)
DECLARE @SHIPDATEENDDATE nvarchar(4000)
DECLARE @DUEDATESTARTDATE nvarchar(4000)
DECLARE @DUEDATEENDDATE nvarchar(4000)
DECLARE @SHOPORDER nvarchar(4000)

SET @PO=NULL
SET @VENDOR=NULL
SET @PARTNUMBER=NULL
SET @SHIPDATESTARTDATE=NULL
SET @SHIPDATEENDDATE=NULL
SET @DUEDATESTARTDATE=NULL
SET @DUEDATEENDDATE=NULL
SET @SHOPORDER=NULL

SELECT PO, Vendor, PartNumber, isnull(DateCreated,'') DateCreated, isnull(DateDue,'') DateDue, 
ShopOrder, Tare, Qty, Outbound, Suffix, RecvQty, 
Balance, Gross, Manifest, ScrapQty, Heat, Lot, MasterPO, 
OriginalQty, [Status], HotCode, HotNote, Notes, QtyNotReturned, NetWt
FROM OurstandingOrdersAll

--Returns the correct data
--WHERE (PO Like '%%' ) 
--AND (Vendor Like '%%' )

----Locks up when it gets to a certain record 
--WHERE (PO Like '%' + isnull(@PO,'') + '%' ) 
--AND (Vendor Like '%' + isnull(@VENDOR,'') + '%' ) 

--Returns the correct data
WHERE (PO Like '%' + isnull(@PO,'') + '%' ) 
OR (Vendor Like '%' + isnull(@VENDOR,'') + '%' ) 

I'm not sure why, but it locks up if I use the "isnull" and the "AND" together, but not when I use the "isnull" and the "OR". Can anyone shed some light on this?


Chris "Is there anything besides programming?"


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>