M
Mike Labosh
In T-SQL, Consider this table:
CREATE TABLE stringTest (
String1 VARCHAR(5),
String2 VARCHAR(5)
)
GO
INSERT StringTest VALUES ('', 'A')
INSERT StringTest VALUES ('A', '')
GO
SELECT
CASE
WHEN String1 > String2
THEN 'String1 Is Greater'
WHEN String2 > String1
THEN "String2 Is Greater
END
GO
Because in T-SQL, it's faster to say:
WHERE String1 > String2
than it is to say:
WHERE String1 <> String2
I believe it's faster because > is SARGable and <> is not. And I only use
this technique when I want to compare to a ZLS, as in
String1 > '' -- faster than String1 <> ''
SOOOOO Then...
Consider this VB Snip:
Private Sub stringGreaterThan()
Dim s1 As String = ""
Dim s2 As String = "A"
Console.WriteLine(Convert.ToBoolean(s1 > s2))
Console.WriteLine(Convert.ToBoolean(s2 > s1))
End Sub
This method yields the same equivalent of it's T-SQL cousin, but does the
performance have the same behavior? i.e.
Are either of these actually faster than the other?
s1 > ""
vs
s1 <> ""
I know I'm nit-picking here, but I have this giant name parser program,
that, under certain conditions needs to sniff individual characters and
strings. I'm already using ByRef and StringBuilder where I can to get
speed, but anything I can conjure up to squeak a few more cycles per
iteration out of this big fat loop would help. 1 ms per iteration processing
a million records would make this thing fly.
--
Peace & happy computing,
Mike Labosh, MCSD
"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane
CREATE TABLE stringTest (
String1 VARCHAR(5),
String2 VARCHAR(5)
)
GO
INSERT StringTest VALUES ('', 'A')
INSERT StringTest VALUES ('A', '')
GO
SELECT
CASE
WHEN String1 > String2
THEN 'String1 Is Greater'
WHEN String2 > String1
THEN "String2 Is Greater
END
GO
Because in T-SQL, it's faster to say:
WHERE String1 > String2
than it is to say:
WHERE String1 <> String2
I believe it's faster because > is SARGable and <> is not. And I only use
this technique when I want to compare to a ZLS, as in
String1 > '' -- faster than String1 <> ''
SOOOOO Then...
Consider this VB Snip:
Private Sub stringGreaterThan()
Dim s1 As String = ""
Dim s2 As String = "A"
Console.WriteLine(Convert.ToBoolean(s1 > s2))
Console.WriteLine(Convert.ToBoolean(s2 > s1))
End Sub
This method yields the same equivalent of it's T-SQL cousin, but does the
performance have the same behavior? i.e.
Are either of these actually faster than the other?
s1 > ""
vs
s1 <> ""
I know I'm nit-picking here, but I have this giant name parser program,
that, under certain conditions needs to sniff individual characters and
strings. I'm already using ByRef and StringBuilder where I can to get
speed, but anything I can conjure up to squeak a few more cycles per
iteration out of this big fat loop would help. 1 ms per iteration processing
a million records would make this thing fly.
--
Peace & happy computing,
Mike Labosh, MCSD
"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane