C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

sql database


Posted Date: 09 Oct 2008      Posted By: divakaran      Member Level: Bronze     Points: 1   Responses: 2



Hi friends,


I want to know the syntax for If elseif statement in Sql and how it should be ended pls help me

pls check this and tell me wats the pro here
***********************************************************************
if(@category)= 1
begin
select top 20 * from educationmaster where isapproved = 1
elseif(@category)= 2
begin
select top 20 * from educationmaster where isapproved = 0
end if
end
elseif(@category)= 3
begin
select top 20 * from educationmaster
end if
end

pls reply me its urgent


thanks and regards'
Divakran
bye
bye





Responses

Author: D.Jeya kumar(JK)    09 Oct 2008Member Level: DiamondRating: 4 out of 54 out of 54 out of 54 out of 5     Points: 6

Hi,


Begin should end with End

check the below modified code



@category varchar(200)
as
if @category = 1
begin
select top 20 * from educationmaster where isapproved = 1
end
else if(@category)= 2
begin
select top 20 * from educationmaster where isapproved = 0
end
else if(@category)= 3
begin
select top 20 * from educationmaster
end



Regards
JK

Note: please rate it if it is usefull



Author: Mathew Philip    09 Oct 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

Hello,

Check the sample code



SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Mathew Philip
-- Create date: 09-Oct-2008
-- Description: Example
-- =============================================
CREATE PROCEDURE MathewsExample (@a INT)
AS
BEGIN

DECLARE @b INT
SET @a = 1

IF @a = 0
BEGIN
SET @b = 10
END
ELSE IF @a = 1
BEGIN
SET @b = 20
END
ELSE
BEGIN
SET @b = 30
END

END
GO




Depending on the requirement you can use ELSE or ELSE IF in the last block of the ELSE IF ladder.

regards
Mathew



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Change Log Tracking according the database updation
Previous : Exception from HRESULT: 0x80040E21
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use