January 24, 2016 at 7:06 pm
Hello Gurus...
I am new to SQL and trying to teach myself to do more than just query.
I have a Stored Procedure that I am attempting to understand and need some help. Can someone explain to me IN ENGLISH what this statement is doing??
IF (ISNULL(@phrase_type, ' ') = ' ')
(I know that the statement is testing whether the variable @phrase_type is null, but what does the " ,' ') = ' ')" do???
And go....
(Thanks in advance!!)
January 24, 2016 at 8:17 pm
You owe it to yourself to make friends with Books On Line ( the help file for SQL Server ). Hidden very carefully under the F1 key. Also, when you're trying to understand what something like this does, take it apart and add a layer at a time.
Run this:
SELECT ISNULL(Null,'This is Null')
Then add the stuff outside of it. And keep building outward when you understand each piece. it's the only way to get your head around TSQL. Practice, practice, practice. And don't be afraid to experiment.
January 25, 2016 at 1:40 am
Tons of materials. As appointed by pietlinden, you can use other sources on web like for example the following 10 lessons on http://sqlmag.com/t-sql/t-sql-101-lesson-1
It's important that you start with one book/site/teaching source etc, and go with it until finishing a cycle.
Igor Micev,My blog: www.igormicev.com
January 25, 2016 at 4:02 am
IT2012 (1/24/2016)
(I know that the statement is testing whether the variable @phrase_type is null
That's not what it's doing. It's part of what it will do, but not all it will do.
Break it up into pieces. You have an IF with a condition and an expression in that condition. So there are two things you need to look at separately.
First, the expression
ISNULL(@phrase_type, ' ')
Once you're happy with what that does, then you have the IF with it's condition
IF (<expression listed above> = ' ')
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 25, 2016 at 9:44 am
Thank you for your responses. They are very much appreciated!!!
January 26, 2016 at 2:46 pm
Here's the clear version of the code:
IF (@phrase_type IS NULL OR @phrase_type = ' ')
Instead, the original code uses:
IF (ISNULL(@phrase_type, ' ') = ' ')
The ISNULL(<value1>, <value2>) will replace a NULL value1 with value2, in this case ' '. If value1 is not null, it will return value1. With some review of the code, you can see that functionally it's the same as the code above, albeit less clear.
SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply