Home Blog Page 9

Correction on bitmask handling

2
In the article on handling bitmasks I posted the other day, I made a fatal error in the splitBitmask function. The function treated the low byte as the first byte, instead of the high byte. Therefore: 0x01 != 0x0001 ... and that is not good! So here's a corrected version...

Dealing with very large bitmasks

8
Continuing in my series of things you should probably not do in SQL Server but sometimes have to, I'm going to do a few posts on dealing with very large bitmasks. Let me first state my utter hatered of bitmasks in databases. I think they're annoying, make the system difficult to understand, and...

Validate a URL from SQL Server

25
File this one in your folder of things you should probably never use -- but maybe, some day, in an emergency, you'll need this. I see posts requesting this functionality all the time. "How do I validate a URL in SQL Server?" Not just the string, but the URL itself -- how can...

Counting occurrences of a substring within a string

23
I have absolutely no idea why anyone wants to do this, but I keep answering the same question in forums: "How do I count the occurrences of a substring within a string?" In an effort to thwart carpal tunnel syndrome, I have created the Ultimate Substring Occurrence Counting UDF. ... And...

Splitting a string of unlimited length

12
There are many techniques for splitting a string in T-SQL (in other words, taking a character-delimited string and producing a table of the values), the best of which are encapsulated in Erland Sommarskog's famous article. My favorite of his string splitting techniques is adapted from a previous example that was created by Anith...

Controlling Stored Procedure Caching with … Dyanmic SQL?!?

8
Tell me if this situation sends a chill down your spine: You've written a stored procedure, tested it against a variety of inputs, and finally rolled it out in production. All is well... Or so you think. You start getting complaints from some users that it's taking forever to return. But other users are...

You REQUIRE a Numbers table!

7
Looking at my list of upcoming articles, I keep seeing the same theme repeated over and over. A sequence table of Numbers. Numbers tables are truly invaluable. I use them all of the time for string manipulation, simulating window functions, populating test tables with lots of data, eliminating cursor logic, and many...

Performance: ISNULL vs. COALESCE

23
Mladen aka spirit1 posted a speed test of COALESCE vs. ISNULL. Reported result: COALESCE is faster. But leave it to Anatoly Lubarsky to argue with what was posted. He posted his own speed test, showing that ISNULL is faster. Anatoly's results showed a miniscule difference, "52 seconds" vs. "52-53...

Rowset string concatenation: Which method is best?

22
Yeah, yeah, yeah, let's get this out of the way right from the start: Don't concatenate rows into delimited strings in SQL Server. Do it client side. Except if you really have to create delimited strings in SQL Server. In which case you should read on. There was a little discussion...

Is PATINDEX faster than LIKE?

6
I keep seeing the same suggestion on various "tips and tricks" websites: For situations in which you might want to use LIKE in the WHERE clause, but for which indexes cannot be used, PATINDEX will perform faster. So, according to these sources, this: SELECT * FROM tbl WHERE PATINDEX('%abc%', col) > 0 is faster...

Popular Posts