can we assign variable to select statement

Database
Enthusiast

can we assign variable to select statement

Create procedure retail.insert12
(
in var1 integer,
in var2 varchar(20)
)

begin
declare n2 integer;
set n2=cast((sel count(*) from retail.emp) as int);=>

i am getting error here(SPL1027:E(L8), Missing/Invalid SQL statement'E(3706):Syntax error: expected something between '(' and the 'sel' keyword.'.)

if
n2<8
then
insert into retail.emp values(var1, var2);
end if;
if
n2>7
then
del from retail.emp where sno=1;
end if;
end;
5 REPLIES
Enthusiast

Re: can we assign variable to select statement

hey thw question is, the table always contian 7 rows.

so whnever i enter 8th row, the old one should be deleted. so i should get latest 7 records
Enthusiast

Re: can we assign variable to select statement

hi guys?
i think the question is not clear wrt?/
Enthusiast

Re: can we assign variable to select statement


The assignment source in a SET statement cannot be a query. I believe you need to write something like this:

select count(*) into n2 from retail.emp;
Enthusiast

Re: can we assign variable to select statement

dude still its not working!!!

Re: can we assign variable to select statement

old thread but try this if you still need

declare n2 integer;
set n2=(sel cast(count(*) as int) from retail.emp);

it worked for me