2017-08-02 2 views
-1

arbeiten, wie Wert in image1 Variablen speichernmysql select Fall nicht mit der Funktion

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 

Antwort

1

Versuchen:

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 
+0

Die Antwort ist nützlich –

+0

seine Arbeiten unter lokalen Sever aber Hauptserver ishows Fehler mit der Meldung " # 2014 - Befehle sind nicht synchron, Sie können diesen Befehl jetzt nicht ausführen "@wchiquito –

+0

@samjadps: Überprüfen Sie [B.5.2.14 Befehle nicht synchron] (https://dev.mysql.com/doc/refman/ 5.7/de/commands-out-of-sync.html). – wchiquito