Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase ««12

Avoiding IF/ELSE Expand / Collapse
Posted Friday, November 16, 2012 11:12 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Today @ 12:49 PM
Points: 660, Visits: 4,532
Thanks all. I went with dwain.c's "normal" catch all query form.
Post #1385797
Posted Friday, November 16, 2012 1:02 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, November 28, 2016 11:55 AM
Points: 1,227, Visits: 3,308
dwain.c (11/15/2012)

It occurred to me on lookback that this is going to fail if #Companies has more than one column or that column has a data type that is incompatible with CompanyID from #CompanyGroups.

Oops ... that's what I get for rushing things probably should have done the following, which was what I had in my head at the time
;with companyNotNull as (
SELECT * FROM #Companies WHERE CompanyID = @CompanyID
companyNull as (
Select CompanyID FROM #CompanyGroups WHERE CompanyGroupID = @CompanyGroupID
FROM companyNotNull
WHERE @companyID is not null
FROM #Companies c
WHERE exists (SELECT 1 FROM companyNull n WHERE n.CompanyID = c.CompanyID)

Post #1385838
Posted Sunday, November 18, 2012 5:35 PM

Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, February 24, 2016 6:28 AM
Points: 3,977, Visits: 6,431
Post deleted. Coffee has not yet arrived.

My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Post #1386115
Posted Monday, November 19, 2012 11:43 AM


Group: General Forum Members
Last Login: Monday, November 28, 2016 10:12 AM
Points: 2,934, Visits: 5,475
CELKO (11/19/2012)

... Companies are identified by a DUNS (we even get radio ads for DUNS here in Austin!);

That is real delight! How cool it is! There is only one small problem here...
Are you sure that most of people on this planet have any idea about where Austin is?
I honestly believe, if everyone would knew that there is a radio ads for DUNS in your place, all of people would try to get to Austin to hear it straight away (may be youtube link at least)!
I can also believe that you have checked every single company in Austin and made sure they have their DUNS done. Including every independent pizza or burger shop...
Sorry to upset you, but unfortunately the rest of the world is not quite in Austin yet, therefore there are still some companies around (and people) who never heard about such a beautiful thing as DUNS, which allows to uniquely identify company on our small planet. Actually, I've worked for quite few large companies who do deal with a lot of corporate clients of any size, and I never, really NEVER! have seen any database where DUNS is used as PK. Actually, before you have mentioned it couple month ago, I have never even heard this word at all. But, of course, it is poor me, living on the outskirts of the world in the middle-of-no-where called London-village...
Oh lucky you...
I will now sleep and dream about real paradise on the earth called Austin, where even radio informs happy citizens about DUNS...

By the way, for many of us rows and records are the same... I'm so sorry...

And to OP, just stick with INT CompanyId's PKs, it's a common sense to use it... until you are from Austin where even radio...

"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1386525
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse