Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

How to use if/else statements in SQL

On Thursday, February 22nd 2007 at 02:15 PM
By Andrew Pociu (View Profile)
***--   (Rated 2.9 with 23 votes)
Advertisement
More SQL Resources
The SQL query language supports if/else statements just like most programming languages, and in a similar fashion.

Example:

IF [Condition]
BEGIN
[Statement]
END
ELSE
BEGIN

[Statement]
END


The main difference is that instead of using the curly brackets - { and } - BEGIN and END satatements are being used.

Following the same flow, an if/else if/else statement looks like this:

IF [Condition]
BEGIN
[Statement]
END
ELSE IF
BEGIN

[Statement]
END

ELSE
BEGIN

[Statement]
END
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this Knowledge Base article
Comment Current Comments
by Anne on Monday, May 28th 2007 at 05:14 PM

Would be more helpful with examples... I suppose it gest the point across though.

by saravanan on Thursday, September 11th 2008 at 01:29 AM

you gave me very essential

by saravanan on Thursday, September 11th 2008 at 01:29 AM

you gave me very essential

by RCA on Tuesday, October 21st 2008 at 08:00 PM

Piece of shit...

can't be believe this stupid article appears at the top in the Google search...

Totally useless

by Chad on Tuesday, December 9th 2008 at 04:10 PM

perfect! Didn't know about the Begin

by Robert on Monday, December 29th 2008 at 12:01 PM

Some please add an example

by JMMJM on Tuesday, May 26th 2009 at 07:24 PM

fking useless

by Non on Tuesday, July 7th 2009 at 10:44 PM

Hay lắm, thanks

by Robert on Thursday, July 23rd 2009 at 09:32 AM

Im saying somthing to join in the rant! Im so coool!

by Pro on Friday, October 9th 2009 at 01:18 AM

This is a completely useless article to appear on the top results of Google search

by Dill on Thursday, October 15th 2009 at 02:01 PM

GARBAGE

by thisishit on Saturday, February 6th 2010 at 10:43 PM

fking useless

by Lee Harvey on Tuesday, March 2nd 2010 at 04:20 PM

I am the FONZ!

by Hang Low on Wednesday, March 3rd 2010 at 01:28 PM

I'm a model you know what I mean, on the cat walk.

by CupidStunt on Tuesday, April 13th 2010 at 11:47 AM

I've added more detail. Hope this helps.

Cupid

IF do some stuff
BEGIN
doing something else or something
END
ELSE
BEGIN
the other thing
END

by Ankit on Monday, June 21st 2010 at 04:21 AM

ompletely useless article.

can't believe that it appear on the top results of Google search.

Now Google Need something extra on itself.

by anoniemuis on Monday, August 30th 2010 at 08:49 AM

for everyone who found this artickle useless and crap. this is the stored procedure way of using if statements. if you want to use some sort of if structure in your querys do it like this:

CAST(CASE WHEN table.field = 1 THEN 0 ELSE 1 END AS int)

by Brad on Saturday, November 20th 2010 at 07:27 PM

Hi
Thanks for the help from this site.
Here is a code example I used to check if a CAR number exists in field CAR. If it does then do nothing. If it doesn't then copy the contents of feild Com2 to field CARNumber then end. Hope this helps someone.
Brad

Private Sub EnteredBy_AfterUpdate()
If [CARNumber] > 0 Then
End
Else: [CARNumber] = [Com2]
End If
End Sub

by Hanan on Saturday, January 29th 2011 at 06:50 PM

create proc Valid_Parent_notExist_Insert
as
begin

declare @parent_name nvarchar(50),@count_name int


set @count_name=(select count(parent_name) from Parent where parent_name=@parent_name


if ([@count_name]>0) then
begin
rollback;
end
else
begin
insert into Parent values(@parent_name,'0000')
commit
end
end

I want to know it is correct or not

by Hanan on Saturday, January 29th 2011 at 06:50 PM

create proc Valid_Parent_notExist_Insert
as
begin

declare @parent_name nvarchar(50),@count_name int


set @count_name=(select count(parent_name) from Parent where parent_name=@parent_name


if ([@count_name]>0) then
begin
rollback;
end
else
begin
insert into Parent values(@parent_name,'0000')
commit
end
end

I want to know it is correct or not

by Hanan on Saturday, January 29th 2011 at 06:50 PM

create proc Valid_Parent_notExist_Insert
as
begin

declare @parent_name nvarchar(50),@count_name int


set @count_name=(select count(parent_name) from Parent where parent_name=@parent_name


if ([@count_name]>0) then
begin
rollback;
end
else
begin
insert into Parent values(@parent_name,'0000')
commit
end
end

I want to know it is correct or not

by Hanan on Saturday, January 29th 2011 at 06:50 PM

create proc Valid_Parent_notExist_Insert
as
begin

declare @parent_name nvarchar(50),@count_name int


set @count_name=(select count(parent_name) from Parent where parent_name=@parent_name


if ([@count_name]>0) then
begin
rollback;
end
else
begin
insert into Parent values(@parent_name,'0000')
commit
end
end

I want to know it is correct or not

by Hanan on Saturday, January 29th 2011 at 06:50 PM

create proc Valid_Parent_notExist_Insert
as
begin

declare @parent_name nvarchar(50),@count_name int


set @count_name=(select count(parent_name) from Parent where parent_name=@parent_name


if ([@count_name]>0) then
begin
rollback;
end
else
begin
insert into Parent values(@parent_name,'0000')
commit
end
end

I want to know it is correct or not

by Hanan on Saturday, January 29th 2011 at 06:51 PM

create proc Valid_Parent_notExist_Insert
as
begin

declare @parent_name nvarchar(50),@count_name int


set @count_name=(select count(parent_name) from Parent where parent_name=@parent_name


if ([@count_name]>0) then
begin
rollback;
end
else
begin
insert into Parent values(@parent_name,'0000')
commit
end
end

I want to know it is correct or not

by Hanan on Saturday, January 29th 2011 at 06:51 PM

create proc Valid_Parent_notExist_Insert
as
begin

declare @parent_name nvarchar(50),@count_name int


set @count_name=(select count(parent_name) from Parent where parent_name=@parent_name


if ([@count_name]>0) then
begin
rollback;
end
else
begin
insert into Parent values(@parent_name,'0000')
commit
end
end

I want to know it is correct or not

by Hanan on Saturday, January 29th 2011 at 06:51 PM

create proc Valid_Parent_notExist_Insert
as
begin

declare @parent_name nvarchar(50),@count_name int


set @count_name=(select count(parent_name) from Parent where parent_name=@parent_name


if ([@count_name]>0) then
begin
rollback;
end
else
begin
insert into Parent values(@parent_name,'0000')
commit
end
end

I want to know it is correct or not

by Hanan on Saturday, January 29th 2011 at 06:51 PM

create proc Valid_Parent_notExist_Insert
as
begin

declare @parent_name nvarchar(50),@count_name int


set @count_name=(select count(parent_name) from Parent where parent_name=@parent_name


if ([@count_name]>0) then
begin
rollback;
end
else
begin
insert into Parent values(@parent_name,'0000')
commit
end
end

I want to know it is correct or not

by Hanan on Saturday, January 29th 2011 at 06:51 PM

create proc Valid_Parent_notExist_Insert
as
begin

declare @parent_name nvarchar(50),@count_name int


set @count_name=(select count(parent_name) from Parent where parent_name=@parent_name


if ([@count_name]>0) then
begin
rollback;
end
else
begin
insert into Parent values(@parent_name,'0000')
commit
end
end

I want to know it is correct or not

by ajay on Wednesday, February 2nd 2011 at 11:53 PM

itz correct

by ajay on Wednesday, February 2nd 2011 at 11:53 PM

itz correct

by Hanan on Thursday, February 3rd 2011 at 12:46 PM

thank for every replay but I have Mis software
on the above example
the writ syntax

create proc <Name_procedure>
@parent_name nvarchar(50) -- //here declare the parameters that come from
as -- // out the procedure
begin

declare @count_name int -- // here declare the parameters that used in
--//procedure

set @count_name=(select count(*) from Parent where parent_name=@parent_name)


if [@count_name]=$0 then

-- Insert statements for procedure here

else
begin
rollback;
return 'this name already exist ';
end


--///I hope that help you

by Sexy linda on Friday, March 11th 2011 at 01:04 AM

very simple example who ever has written it he is on big F**k

by Amex on Tuesday, March 22nd 2011 at 11:19 PM

Dears,

Thanks a LOt for your sharing :)
my Query is working now using your ideas :)

by balance transfer credit card on Wednesday, December 14th 2011 at 10:28 AM

Thanks! Exactly what I was looking for.

by Contextual blogposts on Sunday, December 18th 2011 at 12:00 PM

Since this method only returns the age in years, it should return 0, and i think that's ok because the child is 1 day 0 years old? and thx for instructiv code

other question :
if a child is born this morning what is then most probable date of conception ? Nate,

Minor nitpick, but that could make the calculation incorrect for leap years.


Comment Comment on this Knowledge Base article
Name: Email:
Message:
Knowledge Base Related Knowledge Base Articles
There are no related KB articles.

Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs SQL Job Search
My skills include:

Enter a City:

Select a State:


Advanced Search >>
Ads

From the creators of Geekpedia, a revolutionary new coupon website!

BargainEZ has coupons codes, printable coupons, bargains and it is the leading source of Passbook coupons for iPhone and iPod touch devices.

Coupons
Discover Geekpedia
Other Resources