-1

how to store value in image1 variable

BEGIN
DECLARE image1 VARCHAR(250);
select case when (
            (
                select COUNT(*)
                from profile_images
                where building_id = bid
                    and contractor_id = cid
                ) > 0
            ) then (
                select distinct (image)
                into image1
                from profile_images
                where building_id = bid
                    and contractor_id = cid limit 1
                ) else (
            select distinct (image)
            into image1
            from profile_images
            where contractor_id = cid limit 1
            )

END
RETURN image1;
END
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
samjad ps
  • 45
  • 5

1 Answers1

1

Try:

BEGIN
DECLARE image1 VARCHAR(250);
select case when
            (
                select COUNT(*)
                from profile_images
                where building_id = bid
                    and contractor_id = cid
                ) > 0
              then (
                select distinct (image)
                -- into image1
                from profile_images
                where building_id = bid
                    and contractor_id = cid limit 1
                ) else (
            select distinct (image)
            -- into image1
            from profile_images
            where contractor_id = cid limit 1
            )
END into image1;
RETURN image1;
END
wchiquito
  • 16,177
  • 2
  • 34
  • 45