LEN Vs DataLength in sql server

I was asked this question, “What is the differences between LEN and DATALENGTH in sql server”, a couple of times in last fortnight so I decided to write a post regarding LEN vs DATALENGTH.

LEN: For a string, it will return the number of length of the character used, instead of number of bytes, excludes trailing spaces.

DATALENGTH: For a string, it will return the number of bytes used to represent any expression.
This implies that LEN function will first right trim the string and then returns a count of the characters; whereas the DATALENGTH function does not right trim the string and returns the storage space required for the characters.

The other main difference is that LEN don’t work for Text and nText columns, but DataLength does work.

Let’s have a look at an example:

DECLARE @string nCHAR(8)
SELECT @string =’Count ‘

SELECT LEN(@string) AS [LEN],datalength(@string) AS [DATALENGTH]

The output for LEN is 5 while the output for DataLenght =16. The reason that datalength returns the value 16 is because nvarchar uses 2 bytes to store 1 character by using unicode while varchar is using ascii which requires 1 byte per characters

Search in all stored procedures of a database

A few days ago, I had to rename a database column for some uncontrollable reasons. Well, I searched for all the code pages in the project and replaced the column. But the daunting part was that I didn’t know about all the SPs that used that particular column name. So I had to search for the query which can look through all the stored procedures and display a list of all the stored procedures which contains the database column. This will make it easier for me to replace the old column with the new column name.

The query for searching for a column name in all the stored procedures of a database is:

Select routine_name, routine_definition
from information_schema.routines
where routine_definition like ‘%OldColumn%’
and routine_type=’procedure’

Ashu Solo – First organic search query of my blog

Just like another day, I was looking at google webmasters account for “As I Had It”. I was accessing google webmaster to ensure that there are no crawl errors or missing urls etc. When I navigated to search queries section, I was thrilled to know that finally I have my first organic visitor using google. I looked at the search term – “Ashu Solo” . I was really excited as I had written just 7 posts and its been less than a month since I started blogging.

Ashu Solo - First search query on my blog - As I Had It

A snapshot of my first search query from Google Webmaster

For the moment, I was surprised. Ashu is one of my good friends. I have written about him in one post only. How can google show my website for this keyword? I have not been using this keyword actively in my posts. Instead, till now, my blog is most inclined towards keywords like bucket list, travel and rafting.

I straight forward went to the search feature on my website and searched for Ashu Solo. To my astonishment, nothing concrete showed up. Then I started doubting the undoubtable, Google’s webmaster tool. But just to be sure, I searched for this term in google. It gave me answer, Ashu Solo is a prominent personality( here is the proof 🙂 ). It has nothing to do with my friend Ashu.

Although my blog showed up in google coincidently and I am not sure if I will be using this keyword in any of my future posts. But I am happy that I will be able to remember my first search query as Ashu, my friend, is important part of my life.

Advices I got on- “How to be a great blogger?”

Its been just a fortnight since I started blogging. And advices on How to be a great blogger, are pouring in from all the corners, even from the corners I never anticipated. Let it be family or friends or acquaintances, everyone appears to be a great blogger. And un-believably they have covered almost every aspect of great blogger. Everyone of them tried to make be believe as if each and every one knows blogging(off course except me).

Even if I try I won’t be able to list all of the advices I got as I don’t have stamina to write so long posts(I am new to blogging, remember?). But majority of them give me same advice. Here are the three advices that most of them gave me:

  1. Never get carried away while writing. I argued, I need to be honest with my blog posts. To which his explanation was bang on. He simply said when you write a blog post, don’t publish it there and then. Instead read it again the next day. If you feel you wrote right, then go ahead and publish. But if you don’t feel right about that post, then trash it as you were for sure carried away while writing the post
  2. Don’t write anything about someone that you can’t say face to face to that person. If there is something about someone that inspires you to write a blog post, then it ought to be inspiring enough to talk to that someone face to face.
  3. What so ever you write, just remember that it should not hurt you in future. He even gave me example of Mark Zuckergerg( yep, The Zuckerberg of Facebook). Zuckerberg admitted that in earlier years of Facebook he said “They trust me – dumb fucks”. This statement haunted him many years later when issues related to privacy on Facebook were raised.

Initially I was a bit surprised and annoyed on unwarranted advices. I know I can’t write about good things always. There ought to be some posts about bad and some about worse as well. So I will for sure remember for first and second most common advice. But for third, I am not sure as I know I won’t be able to write false things just to be politically correct. But I will definitely remember this so that I don’t write superficial things.

Orkut: my first social media account

On Monday, June 30, 2014,  google announced the shut down of Orkut: my first social media account.

Although I hardly use Orkut now-a-days but the news made me nostalgic about my final year in college.

College life is just like a dream, you just don’t know how quickly the time flies. It was my final year in college and we all friends knew that life would be damn busy after college. Had it been school, everyone would have thought of getting slam books filled. But then came the Orkut: one of the friends introduced it to our class. And, unbelievably, whole of the class signed up in a single day.

So this way, I and my friends got the taste for our first social media account via Orkut. Like most of my friends, I was also unknown to the social media world. Orkut made us understand what social media is. The whole class added each other as friends, scraps and testimonials started to pour in. We used to search for communities that matched our taste. Our first social media account was made colourful by  beautiful themes, everyone would flaunt a different theme.

Orkut was a miracle for us as it was open and inviting. You could view anyone’s profile, send a friendship request to anyone(err…her ). You could have pictures of your crushes. It was like a new freedom in those days.

In order to say final goodbye to Orkut, I logged in to my Orkut account. As I saw scraps, pictures and testimonials, it felt like a flashback of my final year days. What a lovely days those were. Here is image of my profile today with a message “Orkut will not be available after September 30, 2014”


Snapshot of my first social media account: Orkut

RIP Orkut. You are my first social media account and I thank you for being there with me in my college days.