Nice and helpful article - Thanks. Just Curious...
To select eligible candidates in the first select you say
select * from @Candidates where MeetsEligibility = convert(bit,1);
Why do you convert the 1 into a bit? just saying 1 works. I know that the data type for MeetsEligibility is a bit and I'm just curious if there are efficiencies is converting explicitly like this or is it just a readability thing?
Steve
Excellent article. It's very readable with good examples.
SW_Lindsay (4/20/2010)
Nice and helpful article - Thanks. Just Curious...To select eligible candidates in the first select you say
select * from @Candidates where MeetsEligibility = convert(bit,1);
Why do you convert the 1 into a bit? just saying 1 works. I know that the data type for MeetsEligibility is a bit and I'm just curious if there are efficiencies is converting explicitly like this or is it just a readability thing?
Steve
Avoiding an "Implicit conversion". The literal 1 is an integer, resulting in the underlying field being converted to an integer to do the match... if there is an index on this field, it won't be used. Converting the 1 to a bit avoids the implicit conversion, and allows use of an index if one is present.
Personally, I wish there were system variables @@True and @@False of datatype bit, set to 1/0 respectively.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Thanks for the reply and I would agree those constants would be a great additions!
Michael Meierruth (4/20/2010)
Wayne,You state what I always wanted to hear stated, i.e. that ROW_NUMBER()'s ORDER BY is not the same as the SELECT's ORDER BY. Yet, always - haven't encountered an exception yet, when you perform a SELECT the output is always in the order specified by ROW_NUMBER()'s ORDER BY without the presence of an ORDER BY in the SELECT.
How do you explain that?
i had the same question. is there a performance gain with the explicit conversion?
nvm, answered already :hehe:
So, I've overcome the inability to display columnar formats in SSRS subreports by using ROW_NUMBER() along with some modulus "hack-a-math". Here's a brief use case.
Let's say that a customer can have one or more addresses. Using an SSRS subreport, you'd waste a lot of paper displaying these in one column. But, if you could give each address a "RowNumber" and "ColumnNumber", you could drop the addresses into a matrix using RowNumber and ColumnNumber as your groupings.
This revelation, single handedly, was my greatest self-discovery in SQL code in conjunction with SSRS, if I do say so myself.
-------------------
Brian Zive
Assistant Director, Systems
Business Intelligence Analyst
Massachusetts General Hospital
Development Office
___________________________________
Brian A. Zive
Assistant Director, Systems
Business Intelligence Analyst
Massachusetts General Hospital
Development Office
Great article, thanks for writing it and answering people's questions.
ThomasLL
Thomas LeBlanc, MVP Data Platform Consultant
I see these functions in Oracle queries all the time and only partly understood what was going on - thanks for explaining it the SQL Server way! Now I can translate the Oracleisms!
Wayne, Great article! It came a long ways.
---------------------------------------------------------------------
Use Full Links:
KB Article from Microsoft on how to ask a question on a Forum
Jeff Moden (4/19/2010)
Yowch... the formatting monster hit the code hard on this one. I hope Steve can fix it soon.
I think it's all fixed now... all the code is in one block, and missing spaces have been added back in. Sure makes it a lot easier to read now. Thanks Steve!
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 15 posts - 1 through 15 (of 30 total)
You must be logged in to reply to this topic. Login to reply