April 1, 2010 at 8:52 am
The Dixie Flatline (4/1/2010)
Paul, I think you overlooked this from AJ's post in midstream.The goal of the command is to find string within a wildcard range.
Ah right - must have been all those posts I had to scan over to find the point of the thread...;-) 😛
I'll have another look then.
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 1, 2010 at 9:02 am
DECLARE @Example
TABLE (
Data VARCHAR(10)
COLLATE LATIN1_GENERAL_BIN
UNIQUE NONCLUSTERED
);
SET NOCOUNT ON;
INSERT @Example (Data) VALUES ('10');
INSERT @Example (Data) VALUES ('20');
INSERT @Example (Data) VALUES ('30');
INSERT @Example (Data) VALUES ('40');
INSERT @Example (Data) VALUES ('50');
INSERT @Example (Data) VALUES ('60');
INSERT @Example (Data) VALUES ('70');
INSERT @Example (Data) VALUES ('80');
INSERT @Example (Data) VALUES ('90');
SELECT Data
FROM @Example
WHERE Data COLLATE LATIN1_GENERAL_BIN
BETWEEN '1' + CHAR(1)
AND '5' + REPLICATE(CHAR(255), 9);
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 1, 2010 at 9:14 am
Actually, I like this approach. The only thing I would suggest is to tweak it to accept character strings with a length greater than 1.
BETWEEN @lowParm + CHAR(1)
AND @highParm + REPLICATE(CHAR(255), len(number)-len(@highParm));
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
April 1, 2010 at 9:24 am
The Dixie Flatline (4/1/2010)
Actually, I like this approach. The only thing I would suggest is to tweak it to accept character strings with a length greater than 1.
Yep, it could certainly be made more general.
This is similar to the way the query optimizer (used to) turn a LIKE into a seek in some cases.
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 1, 2010 at 9:36 am
Paul, I'm curious. I understand right-padding the high value with char(255) to simulate a wildcard, but why add CHAR(1) to the low value?
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
April 1, 2010 at 9:43 am
The Dixie Flatline (4/1/2010)
Paul, I'm curious. I understand right-padding the high value with char(255) to simulate a wildcard, but why add CHAR(1) to the low value?
Just concept code, Bob. I didn't work too hard on it 😎
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 1, 2010 at 9:51 am
You've been going without sleep... haven't you?
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
April 1, 2010 at 10:00 am
The Dixie Flatline (4/1/2010)
You've been going without sleep... haven't you?
Heh. 😀
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 1, 2010 at 11:13 am
Paul White NZ (4/1/2010)
DECLARE @Example
TABLE (
Data VARCHAR(10)
COLLATE LATIN1_GENERAL_BIN
UNIQUE NONCLUSTERED
);
SET NOCOUNT ON;
INSERT @Example (Data) VALUES ('10');
INSERT @Example (Data) VALUES ('20');
INSERT @Example (Data) VALUES ('30');
INSERT @Example (Data) VALUES ('40');
INSERT @Example (Data) VALUES ('50');
INSERT @Example (Data) VALUES ('60');
INSERT @Example (Data) VALUES ('70');
INSERT @Example (Data) VALUES ('80');
INSERT @Example (Data) VALUES ('90');
SELECT Data
FROM @Example
WHERE Data COLLATE LATIN1_GENERAL_BIN
BETWEEN '1' + CHAR(1)
AND '5' + REPLICATE(CHAR(255), 9);
Nice concept Paul
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 1, 2010 at 11:22 am
CirquedeSQLeil (4/1/2010)
Nice concept Paul
Not really anything new, as I said...but ok, thanks 🙂
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
Viewing 10 posts - 16 through 24 (of 24 total)
You must be logged in to reply to this topic. Login to reply