do like this you will not get any error, any sql statement should be there between BEGIN and END clause and boolean expression in if clause:-
declare @Player table(value int)
if (1=1)
begin
select 1
end
else if(1=2)
begin
select 2
end
else if(1=3)
begin
select 3
end
else
begin
insert into @Player values (1)
end
Marked as answer by customer22 on Jul 27, 2012 09:42 PM
customer22
Member
67 Points
164 Posts
if condition
Jul 26, 2012 06:49 PM|LINK
Hello:
I have three if condition.
1. if
begin..
end
2. if
begin
end
3. if
begin
end
insert statment....
How to work the way, if 1, 2, 3, will not go to insert statment.
As always, your help is highly appreciated.
inquisitive_...
Contributor
3421 Points
575 Posts
Re: if condition
Jul 26, 2012 07:01 PM|LINK
if(Condtion1 or Condition2 or Condition3)
begin
Insert
End
while(1)
TabAlleman
All-Star
15557 Points
2698 Posts
Re: if condition
Jul 26, 2012 07:06 PM|LINK
1. if
begin..
end
2. else if
begin
end
3. else if
begin
end
else
insert statment....
customer22
Member
67 Points
164 Posts
Re: if condition
Jul 27, 2012 04:08 PM|LINK
Thanks.
I tried
if
begin
end
else if
begin
end
else if
begin
end
else
I got syntax error:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'begin'.
Where missed?
Thanks
TabAlleman
All-Star
15557 Points
2698 Posts
Re: if condition
Jul 27, 2012 04:14 PM|LINK
You will have to post the full code. There is nothing wrong with the syntax of the portion you posted.
jeeveshfulor...
Participant
1528 Points
285 Posts
Re: if condition
Jul 27, 2012 08:01 PM|LINK
do like this you will not get any error, any sql statement should be there between BEGIN and END clause and boolean expression in if clause:-
declare @Player table(value int) if (1=1) begin select 1 end else if(1=2) begin select 2 end else if(1=3) begin select 3 end else begin insert into @Player values (1) endcustomer22
Member
67 Points
164 Posts
Re: if condition
Jul 27, 2012 09:41 PM|LINK
Thanks, I figure it out.