Adding cursor and "if exists"

This is related to the stored proc i posted here:

Right before the Declare c1 Cursor, I need to do a check for userlogin and see if it exists in the database. If not, I need to set it to a value. I know in a stored proc , Declares have to be grouped together on top.
So, anyway i can add this check?

I tired "if exists" with the cursor and it didnt work, so I tried code below. That doesnt give me an error. Then I open s1. But how do i check to see if T1User is in s1 or not?
DECLARE s1 CURSOR WITH RETURN FOR  select T1user from taborder where t1user = UserLogin fetch first 1 rows only;
Declare c1 cursor with return  for select ....
open s1;
open c1;

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

in order to check if the user exists, you don't need to use a cursor,
when you retrieve only a single record you can use a single ton select.
it's easier and better performance wise
try this

declare userInd int

Declare c1 cursor with return  for select ....
select count(*) into userInd from taborder where t1user = UserLogin fetch first 1 rows only;

if userInd = 1 then ...,

else ...
open c1;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CamilliaAuthor Commented:
let me try
CamilliaAuthor Commented:
I have this now:
Declare cursor...
 select count(*) into UserInd from taborder where t1user = UserLogin fetch first 1 rows only;
  If userInd = 0 Then
  set UserLogin ='*System'
 END IF ;  
 OPEN c1;

** why do I get : Keyword END not expected. If I comment out that if-section, it runs fine. I also tried "end;" and not "end if;"
CamilliaAuthor Commented:
thanks, i got it working
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.