Bonjour,

j'ai la requête suivante :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
DECLARE @der_x int, @der_y int, @der_z int
SELECT @der_x = 1
 
SELECT @d_pos_x=a.pos_x,
       @d_pos_y=a.pos_y,
       @bat=bat
FROM table1 a inner join table2 b on a.id = b.id
WHERE b.pos_x=ISNULL(@der_x,-99999999)
  AND b.pos_y=ISNULL(@der_y,-99999999)
  AND b.pos_z=ISNULL(@der_z,-99999999)
 
IF @@ROWCOUNT=0
BEGIN
    SELECT @d_pos_x=a.pos_x,
           @d_pos_y=a.pos_y,
           @bat=bat
    FROM table1 a inner join table2 b on a.id = b.id
    WHERE b.pos_x=ISNULL(@der_x,-99999999)
      AND b.pos_y=ISNULL(@der_y,-99999999)
 
    IF @@ROWCOUNT=0
    BEGIN
        SELECT @d_pos_x=a.pos_x,
               @d_pos_y=a.pos_y,
               @bat=bat
        FROM table1 a inner join table2 b on a.id = b.id
        WHERE b.pos_x=ISNULL(@der_x,-99999999)
    END
END
Y a t-il une meilleure solution d'écriture ?
C'est fonctionnel certes, mais niveau lisibilité ...

Le SGBD utilisé est Sybase.