Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use strcmp in if statement in mysql?

Status
Not open for further replies.

Johnsi George

Programmer
Aug 21, 2017
1
0
0
IN
sample:

Set @login='USC00010';
set @user='USC00010';
select STRCMP(@login,@user);//returns 0
if(STRCMP(@login,@user)= 0)
THEN
//process1
else
//process2
end if;
and the above code throws You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if(STRCMP(@login,@user)= 0)

Actual requirement:

if(//matches)
begin
if exists(select X from X )
begin
if exists(select x from x where y=a)
begin
update x
end
end
else//doesn't match
begin
//process2
end
 
Shouldn't syntax be someting like

Set @login='USC00010';
set @user='USC00010';

Begin

if STRCMP(@login,@user)= 0
THEN
//process1
else
//process2
end if;

End;
Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top