Menu

Saturday, 17 May 2014

Add New Column IN Table



It is used to add new column with datatype in the existing table.

Syntax


ALTER TABLE Employee ADD Column_Name DataType(Data Size)


Example-

Alter Table Employee Add EmployeeCity nvarchar(50)

OutPut


Employee (Before)



Employee (After)

 

Wednesday, 26 March 2014

ROUND() Function in sql server 2008



It is used to find the round value of numerical column.

EmployeeID
EmployeeName
EmployeeSalary
1
Mayank Dixit
5000.89
2
Mona
4899.59
3
Purnima
4000
4
Payal
8000
                                                            employee

In the above table (employee), we want to return round value of numericalfield (EmployeeSalary).

Syntax
SELECT        Column Name1, ROUND (Column Name2, 0) AS SubName
FROM           TableName

Note : '0' define no value after decimal. in place of '0' may be 1 or 2 or any numerical value which define how much numerical value will take place after decimal.

Example

SELECT        EmployeeName, ROUND (EmployeeSalary, 0) AS RoundEmployeeSalary
FROM           Employee

Here RoundEmployeeSalary is a subname (alias) of column.

Output:-

EmployeeID
EmployeeName
EmployeeSalary
1
Mayank Dixit
5001
2
Mona
4900
3
Purnima
4000
4
Payal
8000

Friday, 14 March 2014

LEN() Function in ms sql server 2008


It is used to find the length of name (text field as EmployeeName in table[employee]).it is also count space between textfields.
 
EmployeeID
EmployeeName
1
Mayank Dixit
2
Mona
3
Purnima
4
Payal

                                                     employee

In the above table (employee), we want to return value of textfield (employeename).

Syntax

SELECT        LEN(Column_Name) AS Name_of_the_expression
FROM            table_name;

Example

SELECT        LEN(EmployeeName) AS Length_of_employeename
FROM            Employee;

Here Length_of_employeename is a subname (alias) of column.

Output:-
Length_of_employeename
12
4
7
5