
Wednesday, March 12, 2008

Monday, July 02, 2007

Sunday, November 26, 2006

Saturday, November 18, 2006

Friday, October 27, 2006

Thursday, October 05, 2006
SQL: Return "identity" rowID after inserting data and naming stored procedures
Often times as a developer we all need to insert new records into a table in a database and also retrieve the identity id of the most recently added row. The most common solution to this situation is use @@Identity. Simple eh? No, because @@Identity returns the most recently created identity for your connection. So if there is any other operation going on like a trigger, the identity created by the trigger would be returned instead of yours.
So it is better to use scope_identity() always.
Naming stored procedure with a prefix of sp_ is pretty common, i should say that is the current norm. But Apparently this is a bad habbit because the system databases are the only ones that should be named with prefix sp_. Long story short, SQL server starts looking for any stored procedure with a prefix sp_ in the Master database.
For more on the above feature, go here . Pretty cool dont's info on SQL practices SQL
10/5/2006 5:01:33 AM (GMT Daylight Time, UTC+01:00)
|
|

Sunday, August 20, 2006
SQL Coalesce - underutilized function
There are many days in the life of a programmer, when you need to build a search query based on the some/all fields of user input. This function would return the first non-null value.
Coalesce function could be a perfect fit in such cases. It could replace case statements, ISNULL etc.
The other beauty of Coalesce is it take multiple values, whereas ISNULL can take only two values to compare.
SELECT Name, COALESCE(HomePhone, Mobile, Pager) AS ContactNumber FROM User
would return the first non-null value or null value if all of the values are nullPlease follow here for much more on this.
Coalesce on SqlTeam
Interesting Facts on Coalesce
SQL
8/20/2006 6:15:19 AM (GMT Daylight Time, UTC+01:00)
|
|