Execution procedure stockée sur un select

Fermé
thiouraye Messages postés 7 Date d'inscription mardi 12 juillet 2011 Statut Membre Dernière intervention 20 juillet 2011 - 20 juil. 2011 à 13:59
thiouraye Messages postés 7 Date d'inscription mardi 12 juillet 2011 Statut Membre Dernière intervention 20 juillet 2011 - 20 juil. 2011 à 16:50
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

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
1
thiouraye Messages postés 7 Date d'inscription mardi 12 juillet 2011 Statut Membre Dernière intervention 20 juillet 2011 1
20 juil. 2011 à 16:50
Merci Aby, je vais tester ta solution et je te tiendrais au courant.
1