Bug of the day
-
I've been banging my head against a wall trying to work out why a class in a stored procedure was being skipped.
DECLARE @SuppressionMethod varchar(20)
-- ... lots of code...
SET @SuppressionMethod = 'SkipSuppressedMembers'
If lower(@SuppressionMethod) = 'skipsuppressedmembers'
Begin
...No matter what, the if clause was never entered. Can anyone see the head slapper? It's a groaner.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
well I see this has already been answered but I like to use print to see what variables really are
DECLARE @SuppressionMethod varchar(20)
-- ... lots of code...
SET @SuppressionMethod = 'SkipSuppressedMembers'
print @SuppressionMethod
--returns SkipSuppressedMember -
I've been banging my head against a wall trying to work out why a class in a stored procedure was being skipped.
DECLARE @SuppressionMethod varchar(20)
-- ... lots of code...
SET @SuppressionMethod = 'SkipSuppressedMembers'
If lower(@SuppressionMethod) = 'skipsuppressedmembers'
Begin
...No matter what, the if clause was never entered. Can anyone see the head slapper? It's a groaner.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
In this case, blame can be put on the programming language: it should have warned you of the string overflow. Computers are ill-mannered when they do not tell us about our mistakes that they have spotted.
-
Do you see how smug everyone else is that they can count and you can't? I won't belittle you the way the others have.
Forgive your enemies - it messes with their heads
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
It's to mask the fact they are worse on everything else.
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
-
I've been banging my head against a wall trying to work out why a class in a stored procedure was being skipped.
DECLARE @SuppressionMethod varchar(20)
-- ... lots of code...
SET @SuppressionMethod = 'SkipSuppressedMembers'
If lower(@SuppressionMethod) = 'skipsuppressedmembers'
Begin
...No matter what, the if clause was never entered. Can anyone see the head slapper? It's a groaner.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
SkipSuppressedMembers has 21 chars, not 20. You're comparing lower('SkipSuppressedMember') against skipsuppressedmembers
-
I've been banging my head against a wall trying to work out why a class in a stored procedure was being skipped.
DECLARE @SuppressionMethod varchar(20)
-- ... lots of code...
SET @SuppressionMethod = 'SkipSuppressedMembers'
If lower(@SuppressionMethod) = 'skipsuppressedmembers'
Begin
...No matter what, the if clause was never entered. Can anyone see the head slapper? It's a groaner.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
To feed the trolls and have the string fit in the variable, you might consider increasing the length of said troll variable. Other problems in the code, using 'lower' to do a string comparission in SQL, which is case insensitive (unless you start toying with the collation).
-
I've been banging my head against a wall trying to work out why a class in a stored procedure was being skipped.
DECLARE @SuppressionMethod varchar(20)
-- ... lots of code...
SET @SuppressionMethod = 'SkipSuppressedMembers'
If lower(@SuppressionMethod) = 'skipsuppressedmembers'
Begin
...No matter what, the if clause was never entered. Can anyone see the head slapper? It's a groaner.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
I've been banging my head against a wall trying to work out why a class in a stored procedure was being skipped.
DECLARE @SuppressionMethod varchar(20)
-- ... lots of code...
SET @SuppressionMethod = 'SkipSuppressedMembers'
If lower(@SuppressionMethod) = 'skipsuppressedmembers'
Begin
...No matter what, the if clause was never entered. Can anyone see the head slapper? It's a groaner.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
It should be a SELECT, not a SET?.
Psychosis at 10 Film at 11 Those who do not remember the past, are doomed to repeat it. Those who do not remember the past, cannot build upon it.
No. Take a look at the other zillion responses :)
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
I've been banging my head against a wall trying to work out why a class in a stored procedure was being skipped.
DECLARE @SuppressionMethod varchar(20)
-- ... lots of code...
SET @SuppressionMethod = 'SkipSuppressedMembers'
If lower(@SuppressionMethod) = 'skipsuppressedmembers'
Begin
...No matter what, the if clause was never entered. Can anyone see the head slapper? It's a groaner.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
After fixing the size of the SuppressionMethod, it seems like you will also have a problem with the "if" in that, you are assigning the values, not really checking to see if it is... If lower(@SuppressionMethod) = 'skipsuppressedmembers' Begin Should be... [IMHO] if lower(@SuppressionMethod) == 'skipsuppressedmembers' Begin Just a thought.
-
Very good :thumbsup:
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
I first saw a bug like that in the 1980s, in Fortran. The system fell over on startup on Monday, 2nd September. Hint 1: The office was closed and the system shut down over the weekend. Hint 2: Which month has the longest name (it was English)? (And it wasn't me who did it!)
-
After fixing the size of the SuppressionMethod, it seems like you will also have a problem with the "if" in that, you are assigning the values, not really checking to see if it is... If lower(@SuppressionMethod) = 'skipsuppressedmembers' Begin Should be... [IMHO] if lower(@SuppressionMethod) == 'skipsuppressedmembers' Begin Just a thought.
Member 8382884 wrote:
if lower(@SuppressionMethod) == 'skipsuppressedmembers'
BeginHave you tried entering that in an SQL editor and running it? Just a thought.
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. In the face of ambiguity, refuse the temptation to guess.
-
I've been banging my head against a wall trying to work out why a class in a stored procedure was being skipped.
DECLARE @SuppressionMethod varchar(20)
-- ... lots of code...
SET @SuppressionMethod = 'SkipSuppressedMembers'
If lower(@SuppressionMethod) = 'skipsuppressedmembers'
Begin
...No matter what, the if clause was never entered. Can anyone see the head slapper? It's a groaner.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
Well, aside from the obvious which everyone else has commented on, my first question would be "Why is he checking a value that he just set in the previous statement?" Was there some other code that you omitted?
-
Well, aside from the obvious which everyone else has commented on, my first question would be "Why is he checking a value that he just set in the previous statement?" Was there some other code that you omitted?
RDSchaefer wrote:
Was there some other code that you omitted?
I want to say "yes, obviously" but maybe it wasn't obvious. I didn't see the need to include all my code when showing an example.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
I've been banging my head against a wall trying to work out why a class in a stored procedure was being skipped.
DECLARE @SuppressionMethod varchar(20)
-- ... lots of code...
SET @SuppressionMethod = 'SkipSuppressedMembers'
If lower(@SuppressionMethod) = 'skipsuppressedmembers'
Begin
...No matter what, the if clause was never entered. Can anyone see the head slapper? It's a groaner.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
Yes, I can. It took about thirty seconds.
-
I've been banging my head against a wall trying to work out why a class in a stored procedure was being skipped.
DECLARE @SuppressionMethod varchar(20)
-- ... lots of code...
SET @SuppressionMethod = 'SkipSuppressedMembers'
If lower(@SuppressionMethod) = 'skipsuppressedmembers'
Begin
...No matter what, the if clause was never entered. Can anyone see the head slapper? It's a groaner.
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
first line varchar(21) becoz string contains 21 chars