Execution procedure stockée sur un select

Bonjour,

je souhaiterais recupérer l'identifiant d'un login. je cherche d'abords sur ma 1ere table s'il n'existe pas je cherche sur la 2eme et s'il n'existe pas je cherche sur la 3eme. j'exécute la requête mais ça ne marche pas j'aurai besoin d'un coup de main s'il vous plait.
Merci beaucoup

if exists (select top 1 id_1,1 as espace FROM table1 WHERE emailprof = @emailprof and password = @password)

else if exists (select top 1 id_2,2 as espace FROM table2 WHERE email= @password and password = @password)

else if exists (select top 1 id_3,3 as espace from table3 where email= @password and password = @password)

2 réponses

  1. Merci Aby, je vais tester ta solution et je te tiendrais au courant.
    1. Si j'ai bien compris c'est un truc comme ça que tu veux. Tu peux créer une fonction

      CREATE FUNCTION cherche_id (@emailprof nvarchar (50), @password nvarchar(50))
      returns int
      as

      begin
      declare @identifiant int

      if ((SELECT count(*) FROM table1 WHERE emailprof = @emailprof and password = @password) >0)
      set @identifiant = (SELECT top 1 id_1,1 as espace FROM table1 WHERE emailprof = @emailprof and password = @password)

      if ((SELECT count(*) FROM table2 WHERE emailprof = @emailprof and password = @password) >0)
      set @identifiant = (SELECT top 1 id_2,2 as espace FROM table2 WHERE emailprof = @emailprof and password = @password)

      if ((SELECT count(*) FROM table1 WHERE emailprof = @emailprof and password = @password) >0)
      set @identifiant = (SELECT top 1 id_3,3 as espace FROM table3 WHERE emailprof = @emailprof and password = @password)

      else
      set @identifiant = 0

      return @identifiant
      end