Wednesday, April 23, 2014

Avoid CURSORS?

CURSORS or WHILE loops with temp-tables & counter, what do you prefer, personally and perofrmance wise?
This has been discussed in lots of forums, threads, posts and blogs previously. Many people and experts claim to use the either one and most of them are inclined to WHILE loops, and suggest to avoid CURSORS without any proof and logic.

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