Here is great way to remove "hidden" characters from data being imported in SQL Server. These characters are common when importing flat file data.
MetaDeveloper: Remove Carriage Return, Line Feed, Tab in TSQL: "-- remove carriage return, line feed, and tab from a field in tsql
REPLACE(REPLACE(REPLACE(MyField, CHAR(10), ''), CHAR(13), ''), CHAR(9), '')"
Tuesday, August 12, 2008
Thursday, August 7, 2008
COUNT(*) vs COUNT(1)
I have always used * for queries like this where columns don't really matter because they arent being returned:
SELECT COUNT(*) FROM ...
or
WHERE EXISTS (SELECT * FROM ...
Recently I've seen other SQL developers replacing the * with a 1 in these scenarios. Since the columns aren't really being returned, it there really any advantage to using the 1 over the *?
After researching the issue, I've found that it is really just personal preference. I'll stick with COUNT(*).
snaps & snippets: What's wrong with COUNT(*)?: "One thing is certain, though, select count(1) does not perform any better than select count(*). And I've tried using other constants as well – no change. Is that another myth busted? Can anyone confirm this or prove otherwise?"
SELECT COUNT(*) FROM ...
or
WHERE EXISTS (SELECT * FROM ...
Recently I've seen other SQL developers replacing the * with a 1 in these scenarios. Since the columns aren't really being returned, it there really any advantage to using the 1 over the *?
After researching the issue, I've found that it is really just personal preference. I'll stick with COUNT(*).
snaps & snippets: What's wrong with COUNT(*)?: "One thing is certain, though, select count(1) does not perform any better than select count(*). And I've tried using other constants as well – no change. Is that another myth busted? Can anyone confirm this or prove otherwise?"
Subscribe to:
Comments (Atom)
