Wednesday, January 22, 2014

JOIN

JOIN : Sql Join are used to combine rows from two or more tables.
Different SQL JOINs
  1. Inner Join : Return rows when there is at least one match in both tables.
  2. Left Outer Join : Return all rows from the left table, even if there are no matches in the right table.
  3. Right Outer Join : Return all rows from the right table, even if there are on matches in the left table.
  4. Full Outer Join : Return rows when there is a match in the one of the table.

1st Table –
SELECT * FROM Student
clip_image002
2nd Table –
SELECT * FROM Course
clip_image004
 
1) Inner Join : Return rows when there is at least one match in both tables.
INPUT—

SELECT  Student.Id, Student.Name, Student.City, Student.Mobile,
                Student.Email, Course.Code, Course.Name
FROM Student
INNER JOIN Course ON Student.CourseId=Course.Id;

OUTPUT –
clip_image006

2) Left Outer Join : Return all rows from the left table, even if there are no matches in the right table.
INPUT—

SELECT Student.Id, Student.Name, Student.City, Student.Mobile,
               Student.Email, Course.Code, Course.Name
FROM Student
LEFT OUTER JOIN Course ON Student.CourseId=Course.Id;

OUTPUT—
clip_image008

3) Right Outer Join : Return all rows from the right table, even if there are on matches in the left table.

INPUT –
SELECT Student.Id, Student.Name, Student.City, Student.Mobile,
               Student.Email, Course.Code, Course.Name
FROM Student
RIGHT OUTER JOIN Course ON Student.CourseId=Course.Id;

OUTPUT—
clip_image010

4) Full Outer Join : Return rows when there is a match in the one of the table.
INPUT—

SELECT Student.Id, Student.Name, Student.City, Student.Mobile,
               Student.Email, Course.Code, Course.Name
FROM Student
FULL OUTER JOIN Course ON Student.CourseId=Course.Id;

OUTPUT—
clip_image012



Tuesday, January 21, 2014

How to create a SSIS Project

 

1. Open Bids


Go to Start // Programs // Microsoft SQL Server 2008 R2 and open SQL Server Business Intelligence Development Studio

Below is example using Windows 7 and SQL Server 2008 R2.

clip_image001

1. Create new project
In BIDS select File // New // Project…

clip_image002

You will get new project dialog box where you should:

  • Select Business Intelligence Projects in Project Types
  • Select Integration Services Project in Templates:
  • Give it a name (Try to avoid spaces for compatibility reasons)
  • Remember or change location
  • Click ok to create SSIS Project

clip_image004

Thursday, January 16, 2014

AGGREGATE FUNCTION

The aggregate functions are :-
1) COUNT
2) SUM
3) MAX
4) MIN
5) AVG

INPUT –  SELECT * FROM Salary;

OUTPUT --
 clip_image002

 
1) COUNT Functions used :--
 
SYNTAX – COUNT [ (*) \ (DISTINCT \ ALL) ] (COLUMN NAME)

INPUT – SELECT COUNT(*) FROM Salary;

OUTPUT—

clip_image004

INPUT – SELECT Department, COUNT(FirstName) AS UserName
                FROM Salary
                GROUP BY Department;

OUTPUT—
clip_image006


INPUT – SELECT Position,COUNT(FirstName) AS UserName
                FROM Salary
                GROUP BY Position;

OUTPUT –
clip_image008
 

2) SUM Functions Used :-

SYNTAX – SUM( [DISTINCT] COLUMN NAME)

INPUT – SELECT SUM(Salary),SUM(Bonus)
                FROM Salary;

OUTPUT –
clip_image010


INPUT – SELECT Department,SUM(Salary)+SUM(Bonus)
                FROM Salary
                GROUP BY Department;

OUTPUT –
clip_image012
 

3) MAX Functions Used :-


SYNTAX – MAX( [DISTINCT] COLUMN NAME)



INPUT – SELECT MAX(Salary)
                FROM Salary;

OUTPUT –
clip_image014
 

4) MIN Functions Used :-


SYNTAX – MIN( [DISTINCT] COLUMN NAME)


INPUT – SELECT MIN(Salary)
                FROM Salary;

OUTPUT –
clip_image016
 

5) AVG Functions Used :-


SYNTAX – AVG( [DISTINCT] COLUMN NAME)


INPUT – SELECT Department,AVG(Salary)
                FROM Salary
                GROUP BY Department;

OUTPUT –
clip_image018