Wednesday, April 23, 2014

Fibonacci Series,Factorial in SQL Server using CTE Recursion

-- Factorial

;with fact as (
    select 1 as fac, 1 as num
    union all
    select fac*(num+1), num+1
    from fact
    where num<12)
select fac
from fact
where num=5

-- Fibonacci Series

;with fibo as (
    select 0 as fibA, 0 as fibB, 1 as seed, 1 as  num
    union all
    select seed+fibA, fibA+fibB, fibA, num+1
    from fibo
    where num<12)
select fibA
from fibo

-- Number Sequence: 1 to 10

;with num_seq as (
    select 1 as num
    union all
    select num+1
    from num_seq
    where num<100)
select num
from num_seq
where num < 10

-- Date Sequence: May 2011

;with dt_seq as (
    select cast('5/1/2011' as datetime) as dt, 1 as num
    union all
    select dt+1, num+1
    from dt_seq
    where num<31)
select dt
from dt_seq



for more details http://msdn.microsoft.com/en-us/library/ms190766.aspx
                          http://sqlwithmanoj.com/2011/05/23/cte-recursion-sequence-dates-factorial-fibonacci-series/

Difference between Varchar and Nvarchar data types in SQL Server

This is really an interesting topic for me as well as for many developers who all are working on SQL Server.I have seen many developers who are quite confused in differentiating between Varchar and Nvarchar datatypes.I hope after reading my article, you will be able to answer yourself where to use Varchar and where to use Nvarchar.

So let’s see what is the main difference between Varchar and Nvarchar datatype.

There are mainly two differences between Varchar and Nvarchar data types.
Varchar data type can only store non Unicode values while Nvarchar data type can store Unicode + Non Unicode values.
Varchar data type takes 1 byte per character while Nvarchar data type takes 2 bytes per character.
Unicode Characters :- It is the International standard of a character encoding and decoding that is globally accepted.
All the characters from different languages can be encoded by Unicode standard.

Non Unicode Standard or Traditional Standard:- In earlier days when Unicode characters standard was not there for representation of a character,
We were using ASCII standard that was basically based on American and European languages encoding of characters.

Let’s take an example to understand this fact clearly.

Declare @NameNonUnicode as varchar(100)
Declare @NameUnicode as Nvarchar(100)

Set @NameUnicode='Neeraj Kumar Yadav'
Set @NameNonUnicode ='Neeraj kumar Yadav'

Select @NameNonUnicode as NonUnicode, @NameUnicode as Unicode

Monday, January 13, 2014

String was not recognized as a valid DateTime



if you getting this error .

You can set the culture in the web.config via the globalization tag.


under the  <configuration> 

 <system.web>
      <globalization culture="en-GB"/>
   </system.web>

WYSIWYG Text Editor in asp.net using jquery


Use the script in head tag
  <script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
In the <head> tag of design page  create JavaScript function as:

 <script type="text/javascript">
        bkLib.onDomLoaded(function () {
            new nicEditor({ fullPanel: true }).panelInstance('txtName');
        });    
    </script>
                                               OR
if you use master page then you have to use this script
   <script type="text/javascript">
        bkLib.onDomLoaded(function () {
            new nicEditor({ fullPanel: true }).panelInstance('ctl00_ContentPlaceHolder1_txtName');
        });
   
    </script>
In the <body> Tag place a Textarea

<textarea id="txtName" type="text" class="input_txt" runat="server" style="width: 420px;
                                        height: 60px;"></textarea>

reference link
Click here read article

Monday, June 10, 2013

Tips for Happy Life for software developers..


  1. Drink at least 8 glasses of Water each day.
  2. Eat a good breakfast.
  3. Eat more natural food than packed and processed food. 
  4. Live life with Passion and Energy.
  5. Each day, spend 5 minutes reflecting on your day and see what did GOOD or BAD did you do today.
  6. Your Heart and Soul are your best friends. Always listen to them.
  7. Exercise at least 3 days a week. 1-2 hrs a day.
  8. Sleep well. At least 7 hours a day.  
  9. Don't compare your life to others. You have no idea what their journey is all about.
  10. Don't have negative thoughts or things you cannot control. Instead invest your energy in the positive present moment.
  11. Don't blame others for what you are today. People are in worst situations.
  12. Time is precious. No one knows how much you have. Don't waste it.
  13. Everyone has a positive and a negative side. Look for positive sides in others. Look for negative side in yourself and try to change it.
  14. Make peace with your past so it won't spoil the present.
  15. No one is in charge of your happiness but you.
  16. Just do what you supposed to do. Everything will be just fine.
  17. It takes 43 muscles to frown and 17 to smile. Just smile.
  18. Brush your teeth before you go to bed. Good teeth = Good smile.
  19. Don't delay calling your family and friends.
  20. When you are sick, your family and friends are the one you will need. Stay close to them.
  21. Each day, try to help one person in any way.
  22. Don't judge people by their work. If cleaners don't clean, you will be dirty too.
  23. Don't worry about that you cannot control.
  24. What other people think of you, it's their problem. Why do you care?
  25. Forgiveness is a high road. Adapt it.
  26. In an argument or fight, on one wins. Avoid it. Let you be the little fellow.
  27. For all good things, time is NOW. Do not delay them.
  28. For all bad things, there is always tomorrow. Leave them to tomorrow. Tomorrow never comes.
  29. Great people are same in both good and bad situations.
  30. Don't hate your boss. He has a job to do. If he is being unrealistic, let him know nicely.
  31. In business, no one is enemy. Everybody is trying to do their job. Don't take it personal.
  32. When you don't know what to do, take a break. Meet your good friends.
  33. Writing a good habit. Make a daily to do list J
  34. Do as much as you can do. If you can't, don't stress about it.
  35. Don't blame your parents for anything. You're here because of them.
  36. Before judging anyone, put yourself in their shoes.
  37. When you are down, look at people who are in worse situations.
  38. When you are up, look at people who are higher than you.
  39. Adapt good things from others.
  40. If you have any question, just ask. No question is stupid question.