Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
CREATE OR REPLACE FUNCTION master.test2(tehsil text, district text, state text, flag text)
  RETURNS setof master.population AS
$BODY$
BEGIN


  IF flag='A' THEN
    select Count(*) from master.population where income in('1','2')and statecode=state;
  ELSIF flag='B' THEN
 select Count(*) from master.population where income in('1','2') and statecode=state and districtcode=district ;
   ELSIF flag='C' THEN
  select Count(*) from master.population where income in('1','2') and statecode=state and districtcode=district and tehsilcode=tehsil;
  
 
ELSE
     select Count(*) from master.population where income in('1','2'); 
END IF;

END;
$BODY$
  LANGUAGE plpgsql


Throwing an error:
VB
ERROR:  query has no destination for result data
HINT:  If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT:  PL/pgSQL function master.test2(text,text,text,text) line 6 at SQL statement
Posted
v2

1 solution

i solved it like this:


CREATE OR REPLACE FUNCTION master.test2(tehsil text, district text, state text, flag text)
RETURNS int AS
$BODY$
BEGIN
Declare
ione int;
IF flag='A' THEN
select COALESCE (Count(*))into ione from master.population where income in('1','2')and statecode=state;
ELSIF flag='B' THEN
select COALESCE (Count(*)) into ione from master.population where income in('1','2') and statecode=state and districtcode=district ;
ELSIF flag='C' THEN
select COALESCE(Count(*)) into ione from master.population where income in('1','2') and statecode=state and districtcode=district and tehsilcode=tehsil;


ELSE
select COALESCE (Count(*)) into ione from master.population where income in('1','2');
END IF;

return ione;
END;
$BODY$
LANGUAGE plpgsql
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900