Friday, 16 September 2016

Scrolltop jquery


Scrolltop jquery
 
                     Technology are dynamic , it changes frequently . When we ate attached with web development , web development technology , style , look and feel also changes with time . Earlier we used to build a site with several html pages and put link to navigate among the pages .Now thins have changes . Most of the web pages are large , contain lot of information in a single page .This is due to , with the advancement of technology , internet speed have been very much high . It can pull a large page in a second .Thus most of the maker are trying to build a single page website , contain lots of data. Loading speed does not matter. Some write tutorial , which have a good length.

                       User goes from one portion to another portion of a site , generally they goes from the top to bottom .It is tedious to scroll mouse each time to go top of the site . Jqery scrollTop is a option which drive user to  the top of the serene
 
Here is the full code of a html page
 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<style>
.mycss{
       width:100px;
       height:130px;
       padding:10px;
       text-align:center;
       font-weight: bold;
       color: #444;
       text-decoration: none;
       position:fixed;
       top:75px;
       right:40px;
       display:none;
}
.mycss:hover{
       text-decoration:none;
}
</style>
<body>
<a href="#" class="mycss">Scroll Up ↑</a>
</body>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
 </html>
<script type="text/javascript">
    $(document).ready(function () {

        //Check to see if the window is top if not then display button
        $(window).scroll(function () {
            if ($(this).scrollTop() > 100) {
                $('.mycss').fadeIn();
            } else {
                $('.mycss').fadeOut();
            }
        });
               
        $('.mycss').click(function () {
            $('html, body').animate({ scrollTop: 10 }, 1000);
            return false;
        });

    });
</script>


 Explantion : https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js
This is the link of jqery , we can download also.

mycss : This is the class desined for the button

script : This is the heart of this functionality , $(window).scroll , fires when we scroll widows, here  if  scroll value is more than 100 ,the button will visible.
The second part is $('html, body').animate({ scrollTop: 10 }, 1000);
This tells that html bogy will scrollup to top 10 points at the animation speed of 1000

Output : 

 Step 1

  
Step 2

Step 3




 Step 4

















 


Concatenating Row Values in Transact-SQL, How to Convert ?

Concatenating Row Values in Transact-SQL,  How to Convert ?

                               Microsoft SQL Server is a relational database management system . The main purpose of this software product with the primary function of storing and retrieving data as requested by other software applications—which may run either on the same computer or on another computer across a network , and also works for mobile application.
            
                                    While retrieving data , the Microsoft Sql Server retrieve data base on column name . For example if we write that “Select Surname from tbl_family”. It will retrieve all Surname from family table . It will be row wise , for example Surname1 will come first row , Surname2 will comes in the second rows.

Example :
           Select Surname from tbl_family

Output:
Surname
Surname 1
Surname 2
Surname 3
Surname 4


                  That is Good  . But I can across a form where it was asked , “ Please put , the surname of the family member :“ .I need to give all the surname of the family member in a single row , but Select query was returning in row , that is each Surname in different row . Then what is the solution of this problem ?

                 Suppose , I am designing a report where the same written  “ Please put , the surname of the family member :“ , now I need to put all surname in comma separated line .How to solve the problem ? The are two ways .



THE FIRST WAY:
 I am creating a table

CREATE TABLE tbl_family
(
id            INT IDENTITY,
Surname VARCHAR(500)
)


Now we are inserting values into this table

INSERT INTO tbl_family(Surname)
SELECT 'Surname 1'
UNION
SELECT 'Surname 2'
UNION
SELECT 'Surname 3'
UNION
SELECT 'Surname 4'
UNION
SELECT 'Surname 5'
UNION
SELECT 'Surname 6'
UNION
SELECT 'Surname 7'
UNION
SELECT 'Surname 8'
UNION
SELECT 'Surname 9'
 
No I am declaring a variable


declare @sql VARCHAR(MAX)
SELECT  @sql=''

Now I am building query
SELECT  @sql=@sql+CASE WHEN @sql<>'' THEN ',' ELSE '' END +Surname FROM tbl_family
SELECT @sql

Now the output
Surname 1,Surname 2,Surname 3,Surname 4,Surname 5,Surname 6,Surname 7,Surname 8,Surname 9

You will noticed that separator con be any character or string as you wish .This is a fast way to build string from row data.

THE SECOND WAY:
 This is the smartest method , which I preferred . In this method we need not any variable , we can build such string in query , just using xml and stuff.Let us see the example
 

SELECT STUFF((SELECT ',' + ISNULL(x.Surname,'')
          FROM  tbl_family  x
          FOR XML PATH ('')),1,1,'')

The output will be
Surname 1,Surname 2,Surname 3,Surname 4,Surname 5,Surname 6,Surname 7,Surname 8,Surname 9

Now , FOR XML PATH to the end of a query allows you to output the results of the query as XML elements.

Thursday, 22 October 2015

How to convert the whole string to capital letter in Javascript


How to convert the whole string to capital letter in Javascript ?
toUpperCase--is use for making a string to capital letter
var str="This is a technical blog"
str=str.toUpperCase()
alert(str)
will show "THIS IS A TECHNICAL BLOG"

How to detect OS by javascript ?


How to detect OS by javascript ?

var oprating_system ;
oprating_system=' ';

if (navigator.appVersion.indexOf("X11")!=-1) oprating_system="UNIX";
if (navigator.appVersion.indexOf("Win")!=-1) oprating_system="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) oprating_system="MacOS";
if (navigator.appVersion.indexOf("Linux")!=-1) oprating_system="Linux";

What is JSON.parse ?

What is JSON.parse ?

Returns the Object corresponding to the given JSON text. Takes a well-formed JSON string and returns the resulting JavaScript object.

Example 1
        var obj = jQuery.parseJSON( '{ "name": "John" }' );
        alert( obj.name === "John" );


Example 2
var jsonString = '[{"name":"Manchester GTUG","meetup":"First Monday of every month","tags":["gtug","google","manchester","madlab"]},{"name":"Manchester jQuery Group","meetup":"First Tuesday of every month","tags":["jquery","javascript","jresig","madlab"]},{"name":"Hybrid!","meetup":"First Monday of every month","tags":["jquery","javascript","jresig","madlab"]}]';

var myData = JSON.parse(jsonString);

$(document).ready(function() {
    var $grouplist = $('#groups');
    $.each(myData, function() {
        $('<li>' + this.name + '</li>').appendTo($grouplist);
    });
});

Result :
Manchester GTUG
Manchester jQuery Group
Hybrid!

What is json.stringify ?

What is json.stringify ?

If the stringify method sees an object that contains a toJSON method, it calls that method, and stringifies the value returned. This allows an object to determine its own JSON representation.

Example 1.
       JSON.stringify([1,2,3,4,"open","the","door"]);
Result : produces "[1,2,3,4,"open","the","door"]"

Example 2.

var mangtug = {
        name: "Manchester GTUG",
        meetup: "First Monday of every month",
        tags: ["gtug", "google", "manchester", "madlab"]
    },
    manjquery = {
        name: "Manchester jQuery Group",
        meetup: "First Tuesday of every month",
        tags: ["jquery", "javascript", "jresig", "madlab"]
    },
    hybrid = {
        name: "Hybrid!",
        meetup: mangtug.meetup,
        tags: manjquery.tags
    };

var madlabGroups = [mangtug, manjquery, hybrid];

Result :

[{"name":"Manchester GTUG","meetup":"First Monday of every month","tags":["gtug","google","manchester","madlab"]},{"name":"Manchester jQuery Group","meetup":"First Tuesday of every month","tags":["jquery","javascript","jresig","madlab"]},{"name":"Hybrid!","meetup":"First Monday of every month","tags":["jquery","javascript","jresig","madlab"]}]

Tuesday, 31 March 2015

Joy of Class

CLASS Point to remember
 
*Constructor can not be declare as static

*In a class specified , data or function desined private are accessible to member function 
of the class

*Private data member can be accessed both from the base class and from its derived class

*A nonmember function apart from friend can not access nonpublic member of a class

*Protected members cannot be inherited


*A static variable declared inside a function exits till the execution of that function only


*The members of a class by default are private


*Member function cannot be called from within a constructor


*In case of nested class , enclosing class can directly access the private data member of nested class


*To initialise an object of a class A ,which is a data member of a class B,the construct of A has to be invoked in the constructor of class B


*If a friend function declare inside a class it can access all data members of the class


*A friend function declared insede a class does not need scope resolution operator while defing it


*Member of a derived class can only be accessed by the object or pointer to the same class


*A derived class can access the private members of its public base class directly


*Friend function can be inherited


*A virtual function cannot be declared a friend in another class

 1)How can you prevent your class to be inherited further?
You can prevent a class from being inherited further by defining it with the sealed keyword.

2) Is it possible for a class to inherit the constructor of its base class?
No, a class cannot inherit the constructor of its base class.

3) Can you declare an overridden method to be static if the original method is not static?
No. Two virtual methods must have the same signature.

4) Why is the virtual keyword used in code?
The virtual keyword is used while defining a class to specify that the methods and the properties of that class can be overridden in derived classes.

5) Can you allow a class to be inherited, but prevent a method from being overridden in C#?
Yes. Just declare the class public and make the method sealed.

6) Does .NET support multiple inheritance?
.NET does not support multiple inheritance directly because in .NET, a class cannot inherit from more than one class. .NET supports multiple inheritance through interfaces.

7) Is it possible to execute two catch blocks?
You are allowed to include more than one catch block in your program; however, it is not possible to execute them in one go. Whenever, an exception occurs in your program, the correct catch block is executed and the control goes to the finally block.

8) A structure in C# can implement one or more interfaces. Is it true or false?
Yes, it is true. Like classes, in C#, structures can implement one or more interfaces.

9) What is a static constructor?
Static constructors are introduced with C# to initialize the static data of a class. CLR calls the static constructor before the first instance is created.

The static constructor has the following features:
  • No access specifier is required to define it.
  • You cannot pass parameters in static constructor.
  • A class can have only one static constructor.
  • It can access only static members of the class.
It is invoked only once, when the program execution begins. 


 10)What is Static Method?
It is possible to declare a method as Static provided that they don't attempt to access any instance data or other instance methods.

11)What is New modifiers?
The new modifiers hides a member of the base class. C# supports only hide by signature.

12)What is Sealed modifiers?
Sealed types cannot be inherited & are concrete.
Sealed modifiers can also be applied to instance methods, properties, events & indexes. It can't be applied to static members.

Sealed members are allowed in sealed and non-sealed classes.

13)What is Protected access modifier in C#?
The protected keyword is a member access modifier. It can only be used in a declaring a function or method not in the class ie. a class can't be declared as protected class.

A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declare this member. In other words access is limited to within the class definition and any class that inherits from the class

A protected member of a base class is accessible in a derived class only if the access takes place through the derived class type.


14)What is Internal access modifier in C#?
The internal keyword is an access modifier for types and type members ie. we can declare a class as internal or its member as internal. Internal members are accessible only within files in the same assembly (.dll). In other words, access is limited exclusively to classes defined within the current project assembly.


15)What is a private constructor? Where will you use it?
When you declare a Constructor with Private access modifier then it is called Private Constructor. We can use the private constructor in singleton pattern.If you declare a Constructor as private then it doesn’t allow to create object for its derived class, i.e you loose inherent facility for that class.
Class  A

{
// some code
          Private Void A()
          {

           //Private Constructor
           }

}
 
Class B:A
{
//code
}
B obj = new B();// will give Compilation Error


16)Can we declare private class in a Namespace?
No. If you try to create a private class in a Namespace, Compiler will throw a compile time error “Namespace elements cannot be explicitly declared as private, protected, or protected internal”.

17)What is Early binding and late binding?
Calling a non-virtual method, decided at a compile time is known as early binding. Calling a virtual method (Pure Polymorphism), decided at a runtime is known as late binding.

18)Difference between sealed and static classes
sealed classes:

1)we can create their instances, but cannot inherit them

ex:

sealed class demo
{

}

class abc:demo
{
--Wrong
}

2)They can contain static as well as nonstatic members.

static classes:

1)we can neither create their instances, nor inherit them

ex:
static class Program
{

}

2)They can have static members only.

19)Static methods can not use non static members. True or False.
True

20)Static datamembers should be initialized inside the constructor. True or False.
False. Static datamembers should not be initialised inside constructor.

21)Why can't you specify the accessibility modifier for methods inside the interface?
you are not allowed to specify any accessibility, it's public by default.

22)Can you allow class to be inherited, but prevent the method from being over-ridden?
Yes, just leave the class public and make the method sealed.


23)Can you prevent your class from being inherited and becoming a base class for some other classes?

Yes, that's what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It's the same concept as final class in Java.

24)Can you override private virtual methods?

No, you cannot access private methods in inherited classes.

25)Can you declare the override method static while the original method is non-static?
No, you can't, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.

26)What does the keyword virtual mean in the method definition?
The method can be over-ridden.

27)Can we have Sealed Method in abstarct class ?
Looking at first site the The Keyword Sealed & Abstract are contradictory to each other..In simple terms we can Say Answer is NO.Look the code below

using System;

abstract class A
{
public abstract void Hello();
public sealed void Hi();
}

when we will complie the code.. we will get the Compile time Error as below

'A.Hi()' cannot be sealed because it is not an override..

But the Crux is We can have Sealed methods in abstract class when the abstract class is Dervided class .. for Eg.

using System;

class A
{
public virtual void Hello()
{
Console.WriteLine(" Say Hello");
}

}

abstract class B : A
{
         public sealed override void Hello()
        {
        Console.WriteLine(" Say Hi");
         }

}

class C : B
{

}

class Demo
{
          public static void Main()
         {
            C c1 = new C();
            c1.Hello();// Output is Say Hi
           }
}


28)Can we have an Abstract class without having any abstract method ?

Yes we can have Abstract class without having any abstract method ..

See the code below

using System;
abstract class A
    {
          public void Hello()
          {
            Console.WriteLine(" Say Hi");
           }
}

class B:A
{
}

class Demo
{
         public static void Main()
        {
            B b1 = new B();
           b1.Hello();
        }
}

// Output is Say HI



the class A is abstract class.. but it does not have any abstract methods..

29)Can we define Method Overloading in different classes?
No,we can not define Method Overloading in different classes.It must be on the same class.
As we know that Function Overloading is defined in the same class.
We can understand it by an example:-

Below function are an example of Overloaded Constructor,which are defined on the same class.

public class Person
{
           public Person()
          {
          }

          public Person(int person_id)
         {
         }
}


30)Can Function Overriding be defined in Same Class?
No,Function Overriding can only be defined in different class because it treated as Base and Derived or parent-child relationship.


We can understand it by an example:-
public class Base_Class
{

   public Base_Class()
    {        

    }
    public virtual void display()
    {

        Console.WriteLine("base class");
    }

}

public class Derive_Class:Base_Class
{    public Derive_Class()
    {     

    }

    public override void display()    
   {
        Console.WriteLine("derive class");
    }

}

31)What are the advantages of partial classes?
Following are the advantages of Partial classes:-
1). We can separate User Interface part code and business logic code so that it is easy to read and understand by anybody.
2). More than one developers can work at a time.
3). As Partial classes can be separated then it can again be reunited of compilation.

Wednesday, 5 November 2014

MVC Routing Concept

URL stand for Uniform Resource Locator
for example www.abc.com/directory/emplyee.htm

URI is an identifier for some resource, but a URL gives you specific information as to obtain that resource.URL doesn’t necessarily mean a physical location of a static file on a web server’s
hard drive somewhere ,it means some unique identifier.

Most of the cases Webserver  and then directory and sub directory and file name

But in MVC the method is different
  1. MVC matches controller action rather than file system
  2. MVC also matches outgoing request with  controller action rather than file system

Route definitions start with the URL pattern, which specifies the pattern that the route will match. Along with the route URL, routes can also specify default values and constraints for the various parts of the URL, providing tight control over how and when the route matches incoming request URLs


Application_Start()   method contains a call to a method named the
RegisterRoutes method


 public static void  RegisterRoutes (  RouteCollection routes  )
{
      routes.MapRoute( “example”, “{first}/{second}/{third}”);
}

Routing: /albums /display/123
Result: first = “albums” second = “display” third = “123”
routes.MapRoute(“simple”, “{first}/{second}/{third}”);

The {action} parameter value is used to indicate which method of the controller to call in order
to handle the current request. Note that this method invocation applies only to controller classes
that inherit from the System.Web.Mvc.Controller base class. Classes that directly implement
IController can implement their own conventions for handling mapping code to handle the
request.

Any route parameters other than {controller} and {action} can be passed as parameters to the
action method, if they exist. For example, assuming the following controller:

public class AlbumsController : Controller
{
            public ActionResult Display(int id)
           {
                return View();
            }
}

ROUTE URL PATTERN                           EXAMPLES OF URLS THAT MATCH
{controller}/{action}/{genre}                      /albums/list/rock
service/{action}-{format}                            /service/display-xml
{report}/{year}/{month}                              /{day} /sales/2008/1/23

routes.MapRoute(“simple”, “{controller}/{action}/{id}”,new {id = UrlParameter.Optional});


Multiple default values can be provided. The following snippet demonstrates providing a default
value for the {action} parameter as well:
routes.MapRoute(“simple”, “{controller}/{action}/{id}”, new {id = UrlParameter.Optional, action=”index”});

using System.Web.Routing;

Monday, 3 November 2014

SQL Server 2012 Magic

1)Unusual Sort Orders
         (Order by Contain Case)

SELECT  certificate_id,
                certificate_name,
                certificate_code,
                type_id,
               date_position
                              FROM tbl_sref_train_certificate
                             ORDER BY
                                     CASE
date_position WHEN NULL
                                        THEN type_id
                                   ELSE  date_position  END

2) NULLIF,COALESCE

ISNULL : Returns a null value if the two specified expressions are equal.

SELECT NULLIF(2,2)

Result
----------------------------------------
 NULL

SELECT NULLIF(2,3) 
Result
----------------------------------------
2

COALESCE : coalesce returns the first non-null expression among its arguments.

Example 1
SELECT COALESCE(NULL, NULL, NULL, GETDATE()) 

Result
----------------------------------------
2014-11-02 22:48:40.780

The above example may have single value or four values. If it has single value, then it fills null values with remaining attributes.

---------------------------------------------------------------
column 1              |     column1
----------------------------------------------------------------
 Abc                          NULL
NULL                      Efg
--------------------------------------------------------------

Example 2
 SELECT COALESCE(column 1, column1 )

Result
----------------------------------------
  Abc
 Efg

Example 3
Concatination

---------------------------------------------------------------
Country              |     Currency
----------------------------------------------------------------
India                          Rupee
Japan                         Yen
--------------------------------------------------------------


SELECT  Country ,
                 Currency,
                 COALESCE(Country,Currency)  As Country_Currency

---------------------------------------------------------------
Country              |     Currency     | Country_Currency
----------------------------------------------------------------
India                          Rupee           India Rupee          
Japan                         Yen               Japan Yen                              
--------------------------------------------------------------

3) UNION AND UNION Goof Exapmle

DECLARE @test1 TABLE
(
  ID INT,
  NAME VARCHAR(200)
)
DECLARE @test2 TABLE
(
  ID INT,
  NAME VARCHAR(200)
)

INSERT INTO @test1 VALUES (1,NULL),(2,'India'),(3,'Japan'),(4,NULL)
INSERT INTO @test1 VALUES (1,NULL),(2,'USA'),(3,'Braziln'),(4,NULL),(1,'India')

SELECT ID,NAME FROM @test1
UNION
SELECT ID,NAME FROM @test2

SELECT ID,NAME FROM @test1
UNION ALL
SELECT ID,NAME FROM @test2

Result
----------------------------------------
ID NAME
-----------------------------------------
1    NULL
1    India
2    India
2    USA
3    Braziln
3    Japan
4    NULL

Result
----------------------------------------
ID NAME
-----------------------------------------
1    NULL
2    India
3    Japan
4    NULL
1    NULL
2    USA
3    Braziln
4    NULL
1    India

4)Random Rows Return

SELECT  member_id,
        last_name,
        first_name
 FROM tbl_member
 TABLESAMPLE SYSTEM (1 PERCENT);

Result (1st Execution)
----------------------------------------
102  rows

Result (2st Execution)
----------------------------------------
106  rows

So on...

5)Overriding an IDENTITY Column

CREATE TABLE TEST
(
    ID INT IDENTITY  ,
    COUNTRY VARCHAR(200)
)

INSERT INTO TEST (COUNTRY) VALUES ('India'),('Brazil'),('China')

SELECT * FROM TEST

Result
----------------------------------------
ID NAME
-----------------------------------------
1    India
2    Brazil
3    China



SET IDENTITY_INSERT [Database].TEST
INSERT INTO TEST (COUNTRY) VALUES (4,'Pakistan'),(5,'Irac')


----------------------------------------
ID NAME
-----------------------------------------
1    India
2    Brazil
3    China
4   Pakistan
5   Irac


6) Deleting Rows and Returning the Deleted Rows

CREATE TABLE TEST
(
    ID INT IDENTITY  ,
    COUNTRY VARCHAR(200)
)

INSERT INTO TEST (COUNTRY) VALUES  ( 'India' ),( 'Brazil'  ),(  'China'  ),(  'Nepal'  )

DELETE
FROM TEST
OUTPUT deleted.COUNTRY
WHERE ID=4

7) Inserting Rows and Returning the Inserted Rows

CREATE TABLE TEST
(
    ID INT  ,
    COUNTRY VARCHAR(200)
)

INSERT INTO TEST (ID,COUNTRY)
OUTPUT INSERTED.COUNTRY,INSERTED.ID
VALUES       (1,'India')  ,  (2,'Brazil')  ,  (3,'China')  ,  (4,'Nepal')

8)Updating Data and Returning the Affected Rows

CREATE TABLE TEST
(
    ID INT  ,
    COUNTRY VARCHAR(200)
)

INSERT INTO TEST (ID,COUNTRY)
VALUES (1,'India') , (2,'Brazil') , (3,'China') , (4,'Nepal')


CREATE TABLE TEST1
(
    ID INT  ,
    COUNTRYX VARCHAR(200) NULL
)

INSERT INTO TEST1
VALUES (1,NULL),(2,NULL),(3,NULL),(4,NULL)

SELECT * FROM TEST1

UPDATE A
           SET A.COUNTRYX=B.COUNTRY
           OUTPUT INSERTED.COUNTRYX
FROM  TEST1 A
INNER JOIN TEST B
ON A.ID=B.ID

SELECT * FROM TEST1


9) SoundIndex ...Sound Like

DROP TABLE TEST

CREATE TABLE TEST
(
    ID INT  ,
    COUNTRY VARCHAR(200)
)

INSERT INTO TEST (ID,COUNTRY)
VALUES (1,'India'   )  ,
                (2,'Brazil'  )  ,
                (3,'China'  )  ,
                (4,'Nepal'  )  ,
                (5,'ian'      )  ,
                (6,'en'       )  ,
                (7,'an'       )  ,
                (8,'am'      ) ,
                (9,'em'      ),
                (10,'am'    )



SELECT  top 5 COUNTRY
FROM TEST
WHERE  SOUNDEX(COUNTRY)=SOUNDEX('inI')

Result
----------------------------------------
COUNTRY
-----------------------------------------
ian


10) Merger Statement

CREATE TABLE TEST
(
    ID INT  ,
    COUNTRY VARCHAR(200)
)

INSERT INTO TEST (ID,COUNTRY)
VALUES    (1,'India'),
                   (2,'Brazil'),
                   (3,'China'),
                   (4,'Nepal'),
                   (5,'ian'),
                   (6,'en'),
                   (7,'an'),
                   (8,'am'),
                   (9,'em'),
                   (10,'am')


CREATE TABLE TEST1
(
    ID INT  ,
    COUNTRYX VARCHAR(200) NULL
)


MERGE INTO TEST1 AS C
USING TEST AS CT
        ON C.ID = CT.ID
WHEN MATCHED THEN
    UPDATE SET
      C.COUNTRYX = CT.COUNTRY    
WHEN NOT MATCHED THEN
      INSERT (ID,COUNTRYX)
      VALUES (CT.ID, CT.COUNTRY);
     
SELECT * FROM TEST1

---------------------------------------------------------------------------------
ID COUNTRYX
----------------------------------------------------------------------------------
1    India
2    Brazil
3    China
4    Nepal
5    ian
6    en
7    an
8    am
9    em
9    am

11) Sring Operation 

LEFT & RIGHT

SELECT LEFT  (  'India Govt has started clean india mission.' , 10)
SELECT RIGHT ( 'India Govt has started clean india mission.' , 10) ;

Result
----------------------------------------
(No column name)
-----------------------------------------
 India Govt


Result
----------------------------------------
(No column name)
-----------------------------------------
a mission.


UPPER & LOWER 

SELECT UPPER ( 'India Govt has started clean india mission. '  )
SELECT LOWER 'India Govt has started clean india mission.'  )

Result
----------------------------------------
(No column name)
-----------------------------------------
 INDIA GOVT HAS STARTED CLEAN INDIA MISSION.


Result
----------------------------------------
(No column name)
-----------------------------------------
india govt has started clean india mission.


12) Date Function

ISDATE :valid date or not

 SELECT MyDate ,ISDATE(MyDate) AS IsValiDate
                                    FROM (
                                                 VALUES 'IsValiDate'   ),
                                                                (  '2012-02-14' ),
                                                                (  '2012-01-01T00:00:00'  ),
                                                                (  '2014-12-31T23:59:59.9999999' )
                                               )   dt(MyDate)

 
Result
--------------------------------------------------------------------------------------------
MyDate                                    |                    IsValiDate
-------------------------------------------------------------------------------------------
 IsValiDate                                                              0
2012-02-14                                                             1
2012-01-01T00:00:00                                            1
2014-12-31T23:59:59.9999999                             0

13) @@IDENTITY && SCOPE_IDENTITY 

@@IDENTITY returns the last identity value generated by any table in the current session. If the insert statement fires a trigger that inserts into another table with an identity column, the value returned by @@IDENTITY will be that of the table inserted into by the trigger.
SCOPE_IDENTITY returns the last identity value generated by any table in the current session and scope. In the previous scenario, SCOPE_IDENTITY returns the identity value returned by the first insert statement, not the insert into the second table from the trigger.

CREATE TABLE TEST
(
    IDX INT IDENTITY ,
    ID INT  ,
    COUNTRY VARCHAR(200)
)

INSERT INTO TEST (ID,COUNTRY)
VALUES    (1  ,  'India'  ),
                   (2  ,  'Brazil' ),
                   (3  ,  'China' ),
                   (4  ,  'Nepal' ),
                   (5  ,  'ian'     ),
                   (6  ,  'en'      ),
                   (7  ,  'an'     ),
                   (8  ,  'am'    ),
                   (9  ,  'em'   ),
                   (10 , 'am'   )

 SELECT @@IDENTITY, SCOPE_IDENTITY(), IDENT_CURRENT('dbo.TEST');

14) ESCAPE 

 SELECT access_name FROM tbl_user
 WHERE  access_name LIKE  '%%%' 












all ,value return , no match for wildcard %

Instead, you can try one of the following solutions:

SELECT access_nameFROM tbl_userWHERE 
    access_name LIKE  '%[%]%' 
 

SELECT access_name FROM tbl_user  WHERE
    access_name LIKE '%\%%' ESCAPE '\'







বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...