Thursday, November 15, 2007

Learn ASP.NET

What is ASP.NET?

ASP.NET is a technology for creating dynamic Web applications. It is part of the .NET Framework; you can author ASP.NET applications in most .NET compatible languages, including Visual Basic, C#, and J#. ASP.NET pages (Web Forms) are compiled, providing better performance than with scripting languages. Web Forms allow you to build powerful forms-based Web pages. When building these pages, you can use ASP.NET server controls to create common UI elements, and program them for common tasks. These controls allow you to rapidly build a Web Form out of reusable built-in or custom components, simplifying the code of a page.

ASP.NET combines unprecedented developer productivity with performance, reliability, and deployment.

1.Developer Productivity

a.Easy Programming Model.
ASP.NET makes building real world Web applications dramatically easier. ASP.NET server controls enable an HTML-like style of declarative programming that let you build great pages with far less code than with classic ASP. Displaying data, validating user input, and uploading files are all amazingly easy. Best of all, ASP.NET pages work in all browsers -- including Netscape, Opera, AOL, and Internet Explorer.

b.Flexible Language Options
ASP.NET now supports more than 25 .NET languages (including built-in support for VB.NET, C#, and JScript.NET -- no tool required).
c.Great Tool Support.
VS.NET provides integrated support for debugging and deploying ASP.NET Web applications.
d.Rich Class Framework.
The .NET Framework offers over 4500 classes that encapsulate rich functionality like XML, data access, file upload, regular expressions, image generation, performance monitoring and logging, transactions, message queuing, SMTP mail, and much more!

2.Improved Performance and Scalability
a.
Compiled execution.
ASP.NET will automatically detect any changes, dynamically compile the files if needed, and store the compiled results to reuse for subsequent requests. Dynamic compilation ensures that your application is always up to date, and compiled execution makes it fast.

b.Rich output caching.
ASP.NET output caching can dramatically improve the performance and scalability of your application. When output caching is enabled on a page, ASP.NET executes the page just once, and saves the result in memory in addition to sending it to the user. When another user requests the same page, ASP.NET serves the cached result from memory without re-executing the page. Output caching is configurable, and can be used to cache individual regions or an entire page. Output caching can dramatically improve the performance of data-driven pages by eliminating the need to query the database on every request.

c.Web-Farm Session State.
ASP.NET session state lets you share session data user-specific state values across all machines in your Web farm. Now a user can hit different servers in the web farm over multiple requests and still have full access to her session. And since business components created with the .NET Framework are free-threaded, you no longer need to worry about thread affinity.

3.Enhanced Reliability
ASP.NET ensures that your application is always available to your users.

Memory Leak, DeadLock and Crash Protection. ASP.NET automatically detects and recovers from errors like deadlocks and memory leaks to ensure your application is always available to your users.

Google Android

What is Android?

Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.

Features

  • Application framework enabling reuse and replacement of components
  • Dalvik virtual machine optimized for mobile devices
  • Integrated browser based on the open source WebKit engine
  • Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)
  • SQLite for structured data storage
  • Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)
  • GSM Telephony (hardware dependent)
  • Bluetooth, EDGE, 3G, and WiFi (hardware dependent)
  • Camera, GPS, compass, and accelerometer (hardware dependent)
  • Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE

Android Architecture

The following diagram shows the major components of the Android operating system. Each section is described in more detail below.

Applications

Android will ship with a set of core applications including an email client, SMS program, calendar, maps, browser, contacts, and others. All applications are written using the Java programming language.

Application Framework

Developers have full access to the same framework APIs used by the core applications. The application architecture is designed to simplify the reuse of components; any application can publish its capabilities and any other application may then make use of those capabilities (subject to security constraints enforced by the framework). This same mechanism allows components to be replaced by the user.

Underlying all applications is a set of services and systems, including:

  • A rich and extensible set of Views that can be used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser
  • Content Providers that enable applications to access data from other applications (such as Contacts), or to share their own data
  • A Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files
  • A Notification Manager that enables all applications to display custom alerts in the status bar
  • An Activity Manager that manages the lifecycle of applications and provides a common navigation backstack

For more details and a walkthrough of an application, see Writing an Android Application.

Libraries

Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework. Some of the core libraries are listed below:

  • System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices
  • Media Libraries - based on PacketVideo's OpenCORE; the libraries support playback and recording of many popular audio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG
  • Surface Manager - manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications
  • LibWebCore - a modern web browser engine which powers both the Android browser and an embeddable web view
  • SGL - the underlying 2D graphics engine
  • 3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use either hardware 3D acceleration (where available) or the included, highly optimized 3D software rasterizer
  • FreeType - bitmap and vector font rendering
  • SQLite - a powerful and lightweight relational database engine available to all applications

Android Runtime

Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language.

Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included "dx" tool.

The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management.

Linux Kernel

Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. The kernel also acts as an abstraction layer between the hardware and the rest of the software stack.

Wednesday, November 14, 2007

Blackberry Development Using NetBeans Mobility Pack

With the RIM Blackberry JDE 4.1, you can now build Java ME applications for Blackberry devices using NetBeans Mobility Pack for CLDC/MIDP 5.5.

Requirements

Before you begin, you need to install the following software on your computer:

Setting Up for BlackBerry Development

To set up your NetBeans IDE for Blackberry development, you need to add the Blackberry JDE as a custom platform emulator because there are utilities distributed with the JDE that are not distributed with its emulators.

To do this, you perform three steps:

  1. Add the RIM Blackberry JDE as a custom emulator
  2. Create a Blackberry project
  3. Set the Blackberry as the default device emulator

Adding the RIM Blackberry JDE as a Custom Emulator

To begin, you must register the RIM Blackberry emulator using the Java Platform Manager:

  1. Select Tools > Java Platform Manager from the top navigation bar.
  2. Click the Add Platform button.
  3. Select Custom Java Micro Edition Platform Emulator. Click Next.
  4. The Platform Home should be JDE installation directory (C:\Program Files\Research In Motion\BlackBerry JDE 4.1.0).
  5. You can enter whatever you want for the Platform Name.
  6. Set Device Name to one of the supported devices: 7100g, 7100r, 7100t, 7100v, 7100x, 7250, 7290, 7520,
  7. Keep the Preverify Command as it is.
  8. Modify the Execution and Debugger Commands as shown:
    • Execution Command: cmd /C "cd /D {platformhome}{/}simulator&{device}"
    • Debugger Command: cmd /C "cd /D {platformhome}{/}bin&jdwp"
    Click Next.
  9. The Bootstrap Libraries panel displays a long list of jar files. Select all of the listed files except net_rim_api.jar and click Remove. Click Next.
    Note: If the net_rim_api.jar is not in the list, Click the Add button, and type in or navigate to C:\Program Files\Research In Motion\blackberry JDE 4.1.0\lib\net_rim_api.jar and click Open.
    Then click Next.
  10. In the Sources and JavaDoc panel, click the Add button next to the JavaDoc window and type in or navigate to: C:\Program Files\Research In Motion\BlackBerry JDE 4.1.0\docs\api\. The Java Platform Manager should look like the following graphic:

Click Finish, then click Close.

Creating a Blackberry Project

Next, you create a project for your application:

  1. Choose File > New Project.
  2. Under Categories, choose Mobile. Under Projects, choose Mobile Application. click Next.
  3. Give the project a name, for example MobileApplication2.
    If you do not want a sample MIDlet created for your project, uncheck the "Create Hello MIDlet" check box.
  4. Click Finish to create the Project.
  5. Select the Files Tab in the Explorer window and open the project's build.xml file. Add this (below Image)fragment of code right before the tag at the bottom of the file.
  6. If you would like to extend net.rim.device.api.ui.UiApplication instead of standard MIDlets in your project, then:
  • Remove the highlighted argument line from the build.xml script above.
  • Ignore the warnings in Project Properties / Application Descriptor / MIDlets category when adding a class that does not extend MIDlet.
7. From the Files tab, create a new Empty file, called .alx, and save it into your project folder (on the same level as build.xml!) with the content(below Image). Change the names of course to reflect your application. This is a special file required by Blackberry devices to identify the application details.

Set the Blackberry as the Default Device Emulator

Now you're ready to set the default configuration to emulate a Blackberry device:

  1. Right-click on the project and choose Properties.
  2. In the Platform Properties:
    • Choose Blackberry 4.1 from the Emulator Platform drop-down menu.
    • Choose the Blackberry device emulator from the Device drop-down menu.

At this point, you are ready to write code, build, run, execute, and debug your MIDlet for the BlackBerry.

Note: Once you build your project and the emulator launches, you will need to scroll to the icon for your application, which will be on the main phone screen when the emulator comes up. You can use the arrow keys or click the scroll wheel on the emulator image to navigate to your application icon.

Saturday, October 27, 2007

To Avoid back pain

















Friday, October 26, 2007

Banana



Bananas

Depression :
According to a recent survey undertaken by MIND amongst people suffering from depression, many felt much better after eating a banana. This is because bananas contain tryptophan, a type of protein that the body converts into serotonin, known to make you relax, improve your mood and generally make you feel happier.

PMS :

Forget the pills - eat a banana. The vitamin B6 it contains regulates blood glucose levels, which can affect your mood.

Anemia :

High in iron, bananas can stimulate the production of hemoglobin in the blood and so helps in cases of anemia.

Blood Pressure :

This unique tropical fruit is extremely high in potassium yet low in salt, making it the perfect to beat blood pressure.
So much so, the US Food and Drug Administration has just allowed the banana industry to make official claims for the fruit's ability to reduce the risk of blood pressure and stroke


Brain Power :
200 students at a Twickenham (Middlesex) school were helped through their exams this year by eating bananas at breakfast, break, and lunch in a bid to boost their brain power. Research has shown that the potassium-packed fruit can assist learning by making pupils more alert.

Constipation :

High in fiber, including bananas in the diet can help
restore normal bowel action, helping to overcome the problem without resorting to laxatives.

Hangovers :

One of the quickest ways of curing a hangover is to make a banana milkshake, sweetened with honey. The banana calms the stomach and, with the help of the honey, builds up depleted blood sugar levels,while the milk soothes and re-hydrates your system.

Heartburn :

Bananas have a natural antacid effect in the body, so if you suffer from heartburn, try eating a banana for soothing relief.

Morning Sickness :

Snacking on bananas between meals helps to keep blood sugar levels up and avoid morning sickness.

Mosquito bites :
Before reaching for the insect bite cream, try rubbing the affected area with the inside of a banana skin. Many people find it amazingly successful at reducing swelling and irritation.

Nerves :
Bananas are high in B vitamins that help calm the nervous system. Overweight and at work? Studies at the Institute of Psychology in Austria found pressure at work leads to gorging on comfort food like chocolate and crisps. Looking at 5,000 hospital patients, researchers found the most obese were more likely to be in high-pressure jobs The report concluded that, to avoid panic-induced food cravings, we need to control our blood sugar levels by snacking on high carbohydrate foods every two
hours to keep levels steady

Ulcers :

The banana is used as the dietary food against intestinal disorders because of its soft texture and smoothness. It is the only raw fruit that can be eaten without distress in over-chronicler cases. It also neutralizes over-acidity and reduces irritation by coating the lining of the stomach.

Temperature control:
Many other cultures see bananas as a "cooling" fruit that can lower both the physical and emotional temperature of expectant mothers. In Thailand , for example, pregnant women eat bananas to ensure their baby is born with a cool temperature.

Seasonal = Affective Disorder (SAD) :

Bananas can help SAD sufferers because they contain the natural mood enhancer tryptophan.

Smoking:

Bananas can also help people trying to give up smoking. The B6,B12 they contain, as well as the potassium and magnesium found in them, help the body recover from the effects of nicotine withdrawal.

Stress :

Potassium is a vital mineral, which helps normalize the heartbeat, sends oxygen to the brain and regulates your body's water balance. When we are stressed, our metabolic rate rises, thereby reducing our potassium levels. These can be balanced with the help of a high-potassium banana snack.

Strokes :

According to research in "The New England Journal of Medicine,"eating bananas as part of a regular diet can cut the risk of death by strokes by as much as 40%!

Warts:

Those keen on natural alternatives swear that if you want to kill off a wart, take a piece of banana skin and place it on the wart, with the yellow side out. Carefully hold the skin in place with a plaster or surgical tape!

So, a banana really is a natural remedy for many ills. When you compare it to an apple, it has four times the protein, twice the carbohydrate, three times the phosphorus, five times the vitamin A and iron, and twice the other vitamins and minerals. It is also rich in potassium and is one of the best value foods around. So maybe its time to change that well-known phrase so that we say, "A banana a day keeps the doctor away!"

Wednesday, October 10, 2007

Java Contact Search for Mobiles



QFind is an advanced phone book search application for your mobile. As the search facility integrated to the phonebook on most of the phones are very basic, users usually finds it difficult to retrieve the required contact detail. QFind is capable of searching for phone numbers or number patterns and also contacts name patterns. All these integrated to a very simple interface, QFind is undoubtedly a must have on any java supported phone.

Latest version : 1.2
Size on device : 70 KB
Download size : 64 KB
Requirements : MIDP 2.0 with
JSR75 support
Click IT

Features
Freeware
Contact Number Search
Contact Name Search
Integrated Call/SMS facility
Analyze number patterns
Highlights Search Pattern
Simple interface
Searches Begins With, Contains & Ends With

Thursday, September 20, 2007

mGuard Theft Recovery for Sony-Ericsson Mobiles


mGuard Theft Recovery
mGuard Theft Recovery v.1.1 Platforms: Java (J2ME)
Version: 1.1

Java (J2ME) Sony-Ericsson P800-900 compatible version

mGuard.jar

Size: 69.97 Kb

Download to Mobile: Open wap.GetJar.com with your mobile -> Quick Download -> enter Quick Download Code 20752
Download to PC:
JAD file (mGuard.jad)
JAR file (mGuard.jar)

mGuard provides protection and safety from theft or loosing your device and helps to retrieve it back. Now the users can forget the fear of loosing their device by protecting it using mGuard Software. As of now, mGuard is the world’s only Theft Recovery Software for Java phones(J2ME, JavaME, MIDP devices). mGuard does not rely on Bluetooth, GPRS or GPS for its functionality and hence it can be used on devices and areas where these are unavailable. SMS based Remote Control and spy on the stolen devices will be possible on the next release of mGuard. The complete documentation is available at www.dexmobile.com in PDF format.
Features
* Worlds First Theft Recovery Solution for Java Phones
* Freeware
* SMS notification on SIM Change to predefined number
* Does not affect mobile performance in normal operation
* Complete Stealth operations
* Tiny installation footprint
* Easy Configuration
* Settings Password Protected
Currently Supports Sony Ericsson phones including
K530i
K550 K550i, K550c
K610 K610i, K610c, K618i
K790 K790i, K790c, K790a
K800 K800i, K800c
K810 K810i, K818c
K770,
S500i,S500c
T650i,T650c
W580 W580i, W580c
W610 W610i, W610c
W660 W660i
W710 W710i, W710c
W830 W830i, W830c
W850 W850i, W850c
W880 W880i, W888c
Z310 Z310i, Z310a
Z610 Z610i
Z710 Z710i, Z710c
Z750 Z750i,K850,W910i
Make sure to enable Messaging and autostart permissions after installation. You can get a free unlock code from www.dexmobile.com

Tuesday, August 7, 2007

Java HotSpot Virtual Machine

The Java HotSpot Virtual Machine is a core component of the Java SE platform. It implements the Java Virtual Machine Specification, and is delivered as a shared library in the Java Runtime Environment. As the Java bytecode execution engine, it provides Java runtime facilities, such as thread and object synchronization, on a variety of operating systems and architectures. It includes dynamic compilers that adaptively compile Java bytecodes into optimized machine instructions and efficiently manages the Java heap using garbage collectors, optimized for both low pause time and throughput. It provides data and information to profiling, monitoring and debugging tools and applications.


Tuesday, July 31, 2007

Types of constraints

I focus on four types of constraints: primary key, foreign key, unique, and check. Here's a brief overview of each.

Primary key

This constraint is used to guarantee that a column or set of columns on a table contain unique values for every record in the given table. This lets you ensure data integrity by always being able to uniquely identify the record in the table.

A table can have only one primary key constraint defined on it, and the rows in the primary key columns cannot contain null values. A primary key constraint can be defined when a table is created, or it can be added later.

This script creates a primary key constraint on a single field when the table is created:

IF OBJECT_ID('SalesHistory')>0
DROP TABLE SalesHistory;

GO

CREATE TABLE [dbo].[SalesHistory](
[SaleID] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[Product] [char](150) NULL,
[SaleDate] [datetime] NULL,
[SalePrice] [money] NULL
)

GO

The followings script creates the primary key constraint when the table is created. This method allows you to define a name for the constraint and to create the constraint on multiple columns if necessary.

IF OBJECT_ID('SalesHistory')>0
DROP TABLE SalesHistory;

GO
CREATE TABLE [dbo].[SalesHistory](
[SaleID] [int] IDENTITY(1,1) NOT NULL,
[Product] [char](150) NULL,
[SaleDate] [datetime] NULL,
[SalePrice] [money] NULL,
CONSTRAINT pk_SaleID PRIMARY KEY (SaleID)

)

GO

This script creates the primary key constraint on the table after it is created:

IF OBJECT_ID('SalesHistory')>0
DROP TABLE SalesHistory;

GO



CREATE TABLE [dbo].[SalesHistory](
[SaleID] [int] IDENTITY(1,1) NOT NULL,
[Product] [char](150) NULL,
[SaleDate] [datetime] NULL,
[SalePrice] [money] NULL

)

GO

ALTER TABLE SalesHistory

ADD CONSTRAINT pk_SaleID PRIMARY KEY (SaleID)

GO

Foreign key

This constraint limits the values of columns in one table based upon the values of columns in another table. This link between the two tables requires the use of a "lookup table," which contains the accepted list of values; this list must contain a unique or primary key constraint. After the constraint is established between the two tables, any data modifications to the fields defined in the constraint on the foreign key table will cause a validation to ensure that the data being updated or inserted is contained in the lookup table.

The previous script contains the WITH NOCHECK clause. I use it so that any existing values in the table are not considered when the constraint is added. Any records in the table that violate the newly added constraint will be ignored so that the constraint is created. The constraint will only be applicable to new records entered into the SalesHistory table.

Unique

This constraint guarantees that the values in a column or set of columns are unique. Unique and primary key constraints are somewhat similar because each provide a guarantee for uniqueness for a column or set of columns. A primary key constraint automatically has a unique constraint defined on it.

There are two differences between the constraints: (1) You may have only one primary key constraint per table, yet you may have many unique constraints per table; (2) A primary key constraint will not allow null values but a unique constraint will (although it will only allow one null value per field).

This script creates a unique constraint on the SaleID column when the table is created:

IF OBJECT_ID('SalesHistory')>0
DROP TABLE SalesHistory;

GO
CREATE TABLE [dbo].[SalesHistory](
[SaleID] [int] NOT NULL UNIQUE,
[Product] [char](150) NULL,
[SaleDate] [datetime] NULL,
[SalePrice] [money] NULL

)

GO

The following script creates a unique constraint on the table at creation, and it allows for constraint naming and for defining the unique constraint on multiple columns if necessary.

IF OBJECT_ID('SalesHistory')>0
DROP TABLE SalesHistory;

GO

CREATE TABLE [dbo].[SalesHistory](
[SaleID] [int] NOT NULL,
[Product] [char](150) NULL,
[SaleDate] [datetime] NULL,
[SalePrice] [money] NULL,
CONSTRAINT uc_SaleID UNIQUE (SaleID)

)

GO

This script creates the unique constraint on the SalesHistory table by altering the table after it has been created:

IF OBJECT_ID('SalesHistory')>0
DROP TABLE SalesHistory;

GO

CREATE TABLE [dbo].[SalesHistory](
[SaleID] [int] NOT NULL,
[Product] [char](150) NULL,
[SaleDate] [datetime] NULL,
[SalePrice] [money] NULL

)

GO

ALTER TABLE SalesHistory

ADD CONSTRAINT uc_SaleID UNIQUE(SaleID)

GO

Check

This constraint limits the value range, or domain, in a column. Check constraints check the acceptable values against a logical expression defined in the constraint. These constraints are similar to foreign key constraints in that they both govern the acceptable values for a column or set of columns in a given row in a table. You can create a check constraint at the column or table level. A check constraint on a single column allows only certain values for those columns, while a table check constraint can limit values in certain columns based on values in other fields in the row.

The following script creates a check constraint on the SalePrice column in the SalesHistory table, limiting entries where the SalePrice must be greater than 4. Any attempt to enter a record with the SalePrice present and less than 4 will result in an error.

IF OBJECT_ID('SalesHistory')>0
DROP TABLE SalesHistory;

GO

CREATE TABLE [dbo].[SalesHistory](
[SaleID] [int] NOT NULL,
[Product] [char](150) NULL,
[SaleDate] [datetime] NULL,
[SalePrice] [money] NULL CHECK (SalePrice > 4)

)

GO

Monday, July 23, 2007

SQL Server 2005 Samples (1)

SQL Operatins

/* Example for PRINT */
PRINT 'sample'
Go









/* Example for SELECT */
SELECT 'book', 200;
GO










SELECT 'book' as material, 200 as items;
GO










Variables and Data Types

/*Example for Declare, initialize, display value of a Variable */

DECLARE @varText INT;
SET @varText = 10;
SELECT @varText as varText;
GO










/*Boolean Variable. you can use the BIT or bit keyword.*/
/* initialize 0 -> false or Any number -> true */
DECLARE @varText BIT;
set @varText = 0;
SELECT @varText as varText;
GO










/* Decimal variable */

/* (either decimal or numeric would produce the same effect in SQL Server */

DECLARE @Distance DECIMAL;
SET @Distance = 27.99;
PRINT @Distance;
GO










/* Floating point */
DECLARE @Distance FLOAT;
SET @Distance = 648.16;
PRINT @Distance;
GO










/* Money Variable */
DECLARE @YearlyIncome Money;
SET @YearlyIncome = 48500.15;
SELECT @YearlyIncome AS [Yearly Income];
GO










/* DATETIME Variable */
DECLARE @IndependenceDay DATETIME;
SET @IndependenceDay = '01/01/1960';
SELECT @IndependenceDay AS [Independence Day];
GO










/*Time*/
DECLARE @ArrivalTime datetime;
SET @ArrivalTime = '18:22';
SELECT @ArrivalTime as [Arrival Time];
GO










/*CHAR Variable*/

DECLARE @Gender CHAR, @LeftMostChar CHAR;
SET @GENDER = 'M';
SET @LeftMostChar = 'Male';
SELECT @Gender as Gender, @LeftMostChar as LeftMostChar;
GO











SQL Expressions

/*IF Condition Statement*/

DECLARE @bool BIT;
SET @bool = 0;
IF @bool <> 0
PRINT 'bool value is True';
ELSE
PRINT 'bool value is False';
GO











/*CASE...WHEN...THEN */
DECLARE @CharGender Char(1), @Gender Varchar(20);
SET @CharGender = 'M';
SET @Gender =
CASE @CharGender
WHEN 'm' THEN 'Male'
WHEN 'M' THEN 'Male'
WHEN 'f' THEN 'Female'
WHEN 'F' THEN 'Female'
ELSE 'Unknown'
END;
SELECT @Gender as Gender
GO










/*WHILE Condition Statement*/
DECLARE @Number As int;
SET @Number = 3;
WHILE @Number < style="color: rgb(51, 51, 255);">BEGIN
SELECT @Number as Number;
SET @Number = @Number + 1;
END;
GO











Functions

/* Create Function */

CREATE FUNCTION addition(@a INT, @b INT)
RETURNS INT
AS
BEGIN
DECLARE @result INT;
SET @result = @a + @b;
RETURN @result;
END;
GO

/* Call Function ------*/
DECLARE @Nbr1 INT,
@Nbr2 INT
SET @Nbr1 = 4268
SET @Nbr2 = 26
SELECT @Nbr1 as First,
@Nbr2 as Second,
user.addition(@Nbr1, @Nbr2) as Result;
GO

Built-in Functions

/* Casting a Value */
DECLARE @stringV VARCHAR(10), @intV INT
SET @stringV = '10';
SET @intV = CAST(@stringV as INT);
SELECT @intV as Result
GO

/* Converting a Value */
/* Casting a Value */

DECLARE @stringV VARCHAR(10), @intV INT, @result INT
SET @stringV = '6';
SET @intV = CAST(@stringV as INT);
SET @result = @intV + @intV;
PRINT 'Result :' + CONVERT(VARCHAR(10), @result, 10);
GO










/* The Length of a String */

DECLARE @stringV varchar(10), @result INT
SET @stringV = 'ABCDEF';
SET @result = LEN(@stringV);
PRINT 'Result :' + CONVERT(VARCHAR(10), @result, 10);
GO


/* Date and Time Based Functions*/

























































































Type of Value Abbreviation As a result
Year yy The function will return the number of
years that have elapsed between the start and the end dates
yyyy
quarter q The function will return the number of
quarters of a year that have elapsed between the start and the end
dates
qq
Month m The function will return the number of
months that have elapsed between the start and the end dates
mm
dayofyear y The function will return the number of
days of a year that have elapsed between the start and the end
dates
dy
Day d The function will return the number of
days that have elapsed between the start and the end dates
dd
Week wk The function will return the number of
weeks that have elapsed between the start and the end dates
ww
Hour hh The function will return the number of hours that
have elapsed between the start and the end times or dates
minute n The function will return the number of
minutes that have elapsed between the start and the end times or
dates
mi
second s The function will return the number of
seconds that have elapsed between the start and the end times or
dates
ss
millisecond ms The function will return the number of milliseconds
that have elapsed between the start and the end times or dates

/* The Current System Date and/or Time */

DECLARE @currentDateTime DATETIME
SET @currentDateTime = GETDATE();
SELECT @currentDateTime AS CurrentDateTime;
GO

/*Date/Time Addition
Format :- DATEADD(TypeOfValue, ValueToAdd, DateOrTimeReferenced)*/
DECLARE @Anniversary As DateTime;
SET @Anniversary = '2002/10/02';
SELECT DATEADD(yy, 4, @Anniversary) AS Anniversary;
GO

/*Date/Time Addition
Format :- DATEDIFF(TypeOfValue, StartDate, EndDate) */
DECLARE @DateHired As DateTime, @CurrentDate As DateTime;
SET @DateHired = '2006/10/12';
SET @CurrentDate = GETDATE();
SELECT DATEDIFF(mm, @DateHired, @CurrentDate)
AS [Current Experience], DATEDIFF(dd, @DateHired, @CurrentDate) as Days;
GO