Use this space to put some text. Update this text in HTML

468x60 banner ad

Advertise with Us

Powered by Blogger.

Thursday, 18 February 2016

how-to-filter-for-sql-null-or-empty-string

SQL Null or Empty How to Check for Null or Empty Column in SQL Server SQL

A Not Null  in a database really means the lack of a value. It is a special “value” that you can’t compare to using the normal operators. You have to use a clause in SQL IS Null.

On the other hand, an empty string is an actual value that can be compared to in a database. You simply use two ticks together.

Create Table First in SQL Server


CREATE TABLE [dbo].[Employee](

      [Employee_id] [int] IDENTITY(1,1) NOT NULL,

      [First_name] [nvarchar](300) NULL,

      [Last_name] [nvarchar](300) NULL,

      [Salary] [decimal](20, 2) NULL,

      [Joining_date] [datetime] NULL,

      [Department] [nvarchar](200) NULL

) ON [PRIMARY]
 Insert Record 
 
INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('John', 'Abraham', 1000000.00, 1905-06-07, 'Banking')

INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('Michael', 'Clarke', 800000.00, 1894-06-28, 'Insurance')

INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('Michael', 'Clarke', 800000.00, 1894-06-28, 'Insurance')

INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('Roy', 'Thomas', 700000.00, 1894-06-27, 'Banking')

INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('Tom', 'Jose', 600000.00, 1894-06-27, 'Insurance')

INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('Jerry', 'Pinto', 650000.00, 1894-06-27, 'Insurance')

INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('Philip', 'Mathew', 750000.00, 1894-06-28, 'Services')

INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('TestName1', '123', 650000.00, 1894-06-28, 'Services')
INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('TestName2', 'Lname%', 600000.00, 1894-06-27, 'Insurance')
INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('Yamuna', 'Singh',4000.00, NULL, NULL)
INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('Pankaj', 'Roy', 45000.00, NULL, '')

Show Record

select * from [dbo].[Employee]
 



In this above table, I specifically put in some Department that are both null and empty strings.

Get the NULL values using the IS NULL operator.



select * from [dbo].[Employee]
where [Department] is null

Result


Get the empty string using the empty string.


select * from [dbo].[Employee]

where [Department] = ''

Result
 

  If you want to combine them to search for the SQL null or empty string together and retrieve all of the empty strings and nulls all at once, you could do something like this.

select * from [dbo].[Employee]
where [Department] = ''
or [Department] is null

Result



 
 

 

Tuesday, 16 February 2016

encapsulation-in-c-sharp-with-example


Encapsulation


1. We can combine both behavior and functionality both together with the wrapper of class. This means that a class which has data member as well as method is called encapsulation. 

      2. Dividing each of its classes into two distinct parts: the interface and the implementation.

      3. Class is the best example of encapsulation.



 By using the get and set methods (Accessors and Mutators) 
 
public class Account
{
    private string accoutName;
    
    // get methods
    public string GetAccount()
    {
        return accoutName;
    }
    // Set method
    public void SetAccount(string name)
    {
        accoutName = name;
    }
}
static void Main()
{
    string name ="SAVING_ACCOUNT";
    Account account = new Account();
    account.SetAccount(name);
    name = string.Empty;
    name = account.GetAccount();            
}
 
 
 

abstraction-in-c-sharp-with-example

Abstraction 
To reduce and remove the complexity of programming language we use abstraction.
Each real world entity has behavior and functionality. Behavior should be hidden and functionality should be exposing. 

 

Example-


1.      Do you know the inner details of the Monitor of your PC? What happen when you switch ON Monitor? Does this matter to you what is happening inside the Monitor? No Right, Important thing for you is weather Monitor is ON or NOT. 


2.      When you change the gear of your vehicle are you really concern about the inner details of your vehicle engine? No but what matter to you is that Gear must get changed that’s it.


Example of Abstraction:
using System;

using System.Collections.Generic;

using System.Linq;

namespace abstarction
{
    public abstract class college
    {
        public abstract void BTech();
        public abstract void MBA();
    }
    public class Amity : college
    {
        public override void BTech()
        {
            Console.WriteLine("Amity BTech Fee 81000/-");
        }
        public override void MBA()
        {
            Console.WriteLine("Amity MBA Fee 210000/-");
        }
    }
    public class BhartiBidyapeeth : college
    {
        public override void BTech()
        {
            Console.WriteLine("Bharti-Bidyapeeth BTech Fee 41000/-");
        }
      public override void MBA()
        {
            Console.WriteLine("Bharti-Bidyapeeth MBA Fee 110000/-");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Amity ObjAmity = new Amity();
            ObjAmity.BTech();
            ObjAmity.MBA();
            BhartiBidyapeeth ObjBhartiBidyapeeth = new BhartiBidyapeeth();
            ObjBhartiBidyapeeth .BTech();
            ObjBhartiBidyapeeth.MBA();
            Console.ReadLine();
}
Output-
  Amity BTech Fee 81000/-
  Amity MBA Fee 210000/-
  Bharti-Bidyapeeth BTech Fee 41000/-
Bharti-Bidyapeeth MBA Fee 110000/-

Explanation :-

Ø  From above example we have make one abstract class college and two abstract methods Btech and MBA. Amity and Bharti-Bidyapeeth both are override university course fee.
Ø  College course common for both Amity and Bharti-Bidyapeeth so university method BTech and MBA is abstract.
Ø  Amity and Bharti-Bidyapeeth inherited abstract method so college method must be override here.