I have a stored procedure that is returning a few fields, most containing some customer information, and then 1 more that contains an xslfo “blob” in a text datatype field. I’m trying to optimize a process to ignore the records that don’t have a value in this text datatype field, but when I add this to the where clause:
And cl.CorrespondenceFO IS NOT NULL
And Convert(varchar(1), cl.CorrespondenceFO) <> ''
The query times-out. I realize that the text datatype is being deprecated so I’ll need to convert that column in the future, but I need to get this optimized before that occurs. Are there any suggestions on how I can get this stored procedure to return results with these two additional where clauses added in? TIA
Edit: I have updated the datatypes to varchar(max) and tried all of the suggestions below and the query is still timing-out. Any other suggestions?
I finally got this to work. After taking the suggestions of converting my old text, ntext, and image datatypes to varchar(max), nvarchar(max), and varbinary(max) the query was still timing out. So here’s the fix that worked.
Old version =
Select FieldA, FieldB
From TableA
Where FieldA In (‘value1’, ‘value2’)
And Len(FieldB) > 0 — this is what didn’t work
New version =
Create Table #temp
(
FieldA varchar(10),
FieldB varchar(max)
)
Insert Into #temp
(
FieldA,
FieldB
)
Select FieldA, FieldB
From TableA
Where FieldA In (‘value1’, ‘value2’)
Select *
From #temp
Where Len(FieldB) > 0
Drop Table #temp
(I’m not sure why my formatting isn’t working, sorry)
For some reason, the query always timed-out when I tried to do the Len() check in the original query (may have something to do with the table being greater than 17 million records), so just generating a subset of records to deal with, then checking the Len() of that subset allowed me to get my records in a timely manner.
Thanks all!