IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Firebird Discussion :

Utilisation dans un requête du résultat d'une requête mis dans une colonne avec AS


Sujet :

Firebird

  1. #1
    Invité de passage
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Décembre 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Décembre 2021
    Messages : 8
    Par défaut Utilisation dans un requête du résultat d'une requête mis dans une colonne avec AS
    Bonjour
    La réponse à ma question est peut être évidente pour certain mais je galère depuis plusieurs jour sans trouver de solution qui ne soit pas monstrueuse

    Avant d’exprimer ma question, je vais expliquer le contexte
    La base de données est du type Firebird 2.5
    Dans cette base de données, il y a une table SIGNAUX donc le champ FORMULE est utilisé pour définir le comportement des éléments d’une application.
    Je souhaite déterminer l’élément caractérisé par la formule à l’aide de deux informations
    La formule n’étant pas toujours similaire je ne peux pas utiliser des emplacements fixes de recherche pour obtenir ces informations
    Le champ FORMULE peut être de la forme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    shr(and(S15,112),4)   
                                                                                   shr(and(S9,28),2)  
                                                                                   and(S7,7)
    Pour obtenir la première information j’utilise un CAST d’un SubString pour avoir la valeur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    CAST(SubString(h.FORMULE From (Position( '(S' In h.FORMULE ) +2) 
                                   For ( Position( ',' In h.FORMULE ) - (Position( '(S' In h.FORMULE ) +2 )) 
                                                                                                                             ) AS INTEGER)   As Octet
    Pour obtenir la deuxième information j’utilise un CAST d’un SubString pour avoir la valeur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    CAST(SubString( h.FORMULE From (Position(',' In h.FORMULE ) +1) 
                                   For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 )) 
                                                                                                                          ) AS INTEGER)   As Val_Bits
    Toutefois cette information n’est pas directement exploitable elle représente la somme des poids des bits de l’information et je dois effectuer des tests pour obtenir l’information utile qui est le bit le plus faible
    Exemple : pour une valeur 112 c’est 64 ( pour le bit 6 ) +32 ( pour le bit 5) +16 ( pour le bit 4)
    Pour le moment n’ayant pas trouvé (malgré mes longues recherches) comment exploiter directement la valeur de Valbits et mes connaissances en SQL étant limitées
    je suis obliger de reprendre ma formule pour chaque test
    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
    Case 
                     When ( ( Mod(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                   For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),2) <>0 ) 
                                And ( Mod(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                       For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  
    						                                     ) AS INTEGER),1)=0 )  ) Then 0
     
                         // les tests pour les Bits 1 2 3 4 5 6 non représentés pour gagner de la place
     
                 When ( ( Mod(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                  For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),256) <>0 ) 
                                And ( Mod(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                     For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  
    						                                     ) AS INTEGER),128)=0 )  ) Then 7
    End As Bit_Info
    Pour simplifier l’écrire je voudrai reprendre directement la valeur ValBits dans mon test
    Avec une requête de la forme suivante
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
                 When ( ( Mod(Valbits,2) <>0 ) And ( Mod(Valbits),1)=0 )  ) Then 0
                When ( ( Mod(Valbits,256) <>0 ) And ( Mod(Valbits),128)=0 )  ) Then 7
    Ma question: est-ce possible et si oui comment ?

    Merci d'avoir pris le temps de lire ce message et merci d'avance pour votre réponse si vous pouvez répondre à ma question

  2. #2
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 739
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 739
    Billets dans le blog
    65
    Par défaut
    Bonjour,
    J'ai tout d'abord déplacé le message dans la partie idoine puisque les fonctions numériques binaires sont souvent spécifiques à chaque SGBD

    Ma première réaction à la lecture, c'est : pourquoi ne pas avoir utilisé une fonction externe (UDF) d'un autre côté les nouvelles versions ne recommandent pas cette approche même si c'est toujours possible.
    Il y a longtemps (firebird 1.5) j'avais dévelloppé, avec Delphi, mes propres UDFs pour les opérations binaires je peux, à l'occasion retrouver les codes puis j'ai utilisé, pour d'autres fonctions, les UDF proposées par FreeAdHocUDF (à ma souvenance pour des calculs de formules, fonction qui a désormais disparue )

    Il me semble également qu'il y a une méconnaissance des fonctions numériques binaires incluses depuis la version 2.1 (BIN_AND, BIN_OR etc... à retrouver ici )

    Je ne suis jamais très à l'aise avec les opérations binaires aussi ne vais-je pas me lancer dans du codage surtout que je n'ai pas bien compris ces S15,S7,S9 (des colonnes ?)


    La seconde : quel rapport avec l'alias 'AS' du titre ?

    Enfin, dernier point, car j'ai l'impression que le langage utilisé est Delphi (à l'aune de votre seul autre message) et que vous avez allégrement mélangé du code Delphi au SQL en croisant les doigts avez vous connaissance des champs calculés Delphi ?

  3. #3
    Invité de passage
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Décembre 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Décembre 2021
    Messages : 8
    Par défaut
    Merci pour votre réponse

    le As du titre est lié au fait la colonne généré est nommé avec un AS

    Je voulais autant que possible éviter les UDF

    Pour Info les S17 S9 S5 sont les appellations d'octet dans le message qui est traité

    Mon objectif primaire était d'utiliser la colonne comme une variable pour mémoriser le résultat d'un traitement et ne pas avoir à le reprendre à chaque fois

    Ainsi que faire le maximum de traitement en SQL pour avoir une requête à exploiter hors de Delphi
    ( car comme vous l'aviez deviné les Requêtes SQL sont faite à partir de Delphi et d'un composant permettant l'accès au Base de donnée)
    ( car il arrive que le traitement soit fait manuellement avec flamerobin
    lorsque l'on a pas besoin de l'ensemble des traitements qui sont fait avec l'exécutable delphi
    l'exécutable delphi traite de nombreuses autres parties de cette base de données ainsi que plusieurs autres base de données
    )

    j'avais essayé avec Bin_AND mais cela ne résolvait pas mon problème pour autant, donc pourquoi pas MOD

    Je vais donc utiliser le traitement avec Delphi que j'ai réalisé entre temps ( traitement qui ne traite que cet aspect de la base de données ,pour ne avoir à faire tous les autres traitements )

    ma question originelle n'était visiblement pas clair, je vais donc la reformuler

    peut pas utiliser la valeur d'une colonne qui est le résultat d'une requête et si oui comment ?

    C'était la dernière partie de mon message

    Cordialement

  4. #4
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 739
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 739
    Billets dans le blog
    65
    Par défaut
    Citation Envoyé par Alain_91 Voir le message
    Je voulais autant que possible éviter les UDF

    Pour Info les S17 S9 S5 sont les appellations d'octet dans le message qui est traité

    Mon objectif primaire était d'utiliser la colonne comme une variable pour mémoriser le résultat d'un traitement et ne pas avoir à le reprendre à chaque fois
    C'est bien pour cela que j'indiquais ma première réaction : dans mes UDF j'avais créé une fonction DE MEMOIRE f_isbitset syntaxe ISBITSET(SIGNALFIELD,S17) qui renvoyait un entier (0 ou 1) donc facile à gérer même hors programme. Cette UDF on le retrouve dans FreeAdhocUDF avec
    F_BIN_GET Entrée/Sortie compatibles avec rFunc (GETBIT)
    Entrypoint r_getbit Compatibles UTF-8
    Entrée INTEGER
    INTEGER Nombre entier
    binaire cherché
    Sortie INTEGER paramètre 2 - binaire nombre entier
    Il s'agirait de version récente de Firebird (3,4 ou 5) utiliser une FONCTION STOCKEE serait possible. Perso, je tique quand je vois une boucle FOR dans une query

    Cela étant, je me suis pris au jeu : si l'objectif est bien de trouver le numero de bit de poids faible j'ai pondu un test flamerobin
    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
     
    SET TERM #;
    EXECUTE block
    RETURNS (BITFAIBLE INTEGER)
    AS 
    DECLARE SIGNAL BIGINT = 128; 
    BEGIN
    SELECT case 
       WHEN BIN_AND(:SIGNAL,2)=2 THEN 1  -- OU BIN_AND(:SIGNAL,-:SIGNAL)=POWER(2,2)
       WHEN BIN_AND(:SIGNAL,4)=4 THEN 2 
       WHEN BIN_AND(:SIGNAL,8)=8 THEN 3
       WHEN BIN_AND(:SIGNAL,16)=16 THEN 4    
       WHEN BIN_AND(:SIGNAL,32)=32 THEN 5
       WHEN BIN_AND(:SIGNAL,64)=64 THEN 6 
       WHEN BIN_AND(:SIGNAL,128)=128 THEN 7
       WHEN BIN_AND(:SIGNAL,256)=256 THEN 8
       WHEN BIN_AND(:SIGNAL,512)=512 THEN 9       
       WHEN BIN_AND(:SIGNAL,1024)=1024 THEN 8
       ELSE 0
      END  
    FROM RDB$DATABASE INTO :BITFAIBLE;
    SUSPEND;
    END#
    SET TERM ; #
    mais le plus optimisé et court serait certainement d'utiliser SELECT BIN_AND(SIGNAL,-SIGNAL) FROM LATABLE et de traiter ensuite le résultat (0,2,4,8.....) au lieu de vouloir à tout prix obtenir le numéro du bit

  5. #5
    Invité de passage
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Décembre 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Décembre 2021
    Messages : 8
    Par défaut
    Merci pour votre nouvelle réponse

    désolé, mais j'ai encore malheureusement besoin d'explication complémentaire du fait de mes connaissances limitées en SQL

    le champ h.FORMULE de la table SIGNAUX ( From Signaux h ) ne fournit pas un Integer mais un String c'est pour cela que j'utilise
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    CAST(SubString( h.FORMULE From (Position(',' In h.FORMULE ) +1) 
                                   For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 )) ) AS INTEGER)
    je ne comprend malheureusement pas où je doit mettre cette partie de code dans votre code de test pour l'adapter à mes besoins


    Entre temps j'ai refait des tests
    et contrairement à ma justification dans un précédent message pour expliquer l'utilisation de MOD
    l'utilisation de BIN_AND simplifie un peut les tests
    mais ne règle pas la nécessité de réutiliser le Code ci-dessus pour chaque partie du test

    au lieu de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
       When ( ( Mod(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                   For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),2) <>0 ) 
                                And ( Mod(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                       For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))   ) AS INTEGER),1)=0 )  ) Then 0
    J'ai
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
          When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                       For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),1) =1)  Then 0


    Pour info Le numéro du bit le plus faible est la champ utilisé dans une requête SQL sur une table d'une autre base de données
    avec laquelle je cherche à faire un lien, c'est pour cela que je le recherche plutôt que sa valeur


    A ce stade la requête expurgé des conditions de liaisons est la 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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
     
    SELECT  h.FORMULE , 
               Case 
                  When Position( ',x',h.FORMULE) <>0 
                     Then ( 
                           (  CAST(SubString(h.FORMULE From (Position( '(S' In h.FORMULE ) +2) 
                             For ( Position( ',' In h.FORMULE ) - (Position( '(S' In h.FORMULE ) +2 ))   ) AS INTEGER)   -4  ) *8 
                        + Cast(  Case 
                                     When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'F' ) Then 0
                                      When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'E' ) Then 1
                                     When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'D' ) Then 0
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'C' ) Then 2
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'B' ) Then 0
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'A' ) Then 1
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '9' ) Then 0
                                   When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                              For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '8' ) Then 3
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '7' ) Then 0
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '6' ) Then 1
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '5' ) Then 0
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '4' ) Then 2
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '3' ) Then 0
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '2' ) Then 1
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3)
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '1' ) Then 0When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                      For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'F' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                      For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'E' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'D' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'C' ) Then 6
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2)
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'B' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'A' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '9' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '8' ) Then 7
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '7' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '6' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '5' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '4' ) Then 6
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '3' ) Then 4
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '2' ) Then 5
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '1' ) Then 4
                               end 
                         AS INTEGER ) )Else (
                        ( CAST(SubString(h.FORMULE From (Position( '(S' In h.FORMULE ) +2) 
                               For ( Position( ',' In h.FORMULE ) - (Position( '(S' In h.FORMULE ) +2 ))  )      AS INTEGER)   -4) *8 
                        + Case 
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),1) <>0 )  Then 0
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),2) <>0 )  Then 1
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),4) <>0 )  Then 2
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),8) <>0 )  Then 3
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),16) <>0 )  Then 4
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),32) <>0 )  Then 5
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),64) <>0 )  Then 6
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),128) <>0 )  Then 7
                         end )
           End   As Bit_Info
    FROM    SIGNAUX h

    ce qui est relativement long et comporte des réutilisation du même code à chaque test ce que je voudrai éviter

    Cordialement

  6. #6
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 739
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 739
    Billets dans le blog
    65
    Par défaut
    Bon, selon ce que j'ai enfin compris c'est que votre champ est un texte, bêtement, je croyais que vous utilisiez un Entier contenant tous les signaux binaires (pour moi un ENTIER peux stocker au moins 31 signaux question d'économie d'octets), jamais il ne me serait venu à l'idée de faire ce que vous décrivez

    S'agissant d'un texte je partirai sur des expressions régulières donc SIMILAR TO mais comme je n'arrive pas à comprendre la valeur de "Formule" surtout que, encore plus étrange je vois désormais des Lettres (ABCDEF) donc de l'hexadecimal probable donc une colonne résultat qui devrait être quoi ?

  7. #7
    Invité de passage
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Décembre 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Décembre 2021
    Messages : 8
    Par défaut
    Bonjour Sergio
    merci de bien vouloir prendre sur votre temps ( bien qu'à la retraite) pour m'aider à résoudre mon problème
    Je ne suis pas le concepteur de la Base de Données qui sert à paramétrer une application, je n'en suis que l'utilisateur, je dois donc faire avec !

    il y a une trentaine d'élément à visualiser et 19 octets dans le message qui défini les éléments

    Chaque formule défini la valeur d'un élément , qui doit être visualisé à partir de cet valeur
    la valeur est le résultat du calcul avec un octet ( S15 pas exemple ) un masque car l'octet ne représente pas que cet élément et parfois un décalage selon le position de l'information

    Le masque peut être une valeur décimal ou une valeur Hexadécimal ( c'est l'objet du test de la position de x et du traitement différentié)

    Le traitement de l'octet (S15 par exemple ) permet de déterminer l'octet du message
    Le traitement du masque permet de déterminer la position de l'information dans l'octet

    Comme il y a 4 octets Header je soustrait 4 et je multiple par 8 pour avoir la valeur en bit
    auquel j'ajoute la position du bit le plus faible pour avoir finalement la valeur bit_Info qui correspond à la position de l'information
    qui me sert dans une autre Base de Données pour avoir la localisation de l'élaboration de l'information transmise dans le message

    il aurait sans doute été nécessaire de préciser cela dès le début mais je pensais que cela nuirait à la compréhension de mon problème
    qui est d'éviter de reprendre le résultat d'un traitement fournissant la valeur à partir du texte

    l'utilisation de SIMILAR TO ne semble pas répondre à mon objectif à moins que je n'ai pas bien compris son utilisation

    je vais en rester là et considérer le sujet comme clos pour moi
    mais avec l'objectif non atteint ( c'est pour cela que je n'ai mis Résolu )

    Cordialement et encore merci pour votre aide

  8. #8
    Membre Expert
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Septembre 2016
    Messages
    994
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : Conseil

    Informations forums :
    Inscription : Septembre 2016
    Messages : 994
    Par défaut
    Citation Envoyé par Alain_91 Voir le message
    Pour simplifier l’écrire je voudrai reprendre directement la valeur ValBits dans mon test
    Avec une requête de la forme suivante
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
                 When ( ( Mod(Valbits,2) <>0 ) And ( Mod(Valbits),1)=0 )  ) Then 0
                When ( ( Mod(Valbits,256) <>0 ) And ( Mod(Valbits),128)=0 )  ) Then 7
    Je comprends que vous voulez simplifier l'écriture de la requête.
    Si c'est bien ça alors il y a 2 écritures possibles :
    • Utiliser une CTE = le mot clé WITH
    • Faire une sous requête nommée


    Sur le principe c'est la même chose.
    La syntaxe avec WITH est plus "maintenable", à mon goût.

    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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
     
    With Ma_cte as (
       SELECT  h.FORMULE , 
               Case 
                  When Position( ',x',h.FORMULE) <>0 
                     Then ( 
                           (  CAST(SubString(h.FORMULE From (Position( '(S' In h.FORMULE ) +2) 
                             For ( Position( ',' In h.FORMULE ) - (Position( '(S' In h.FORMULE ) +2 ))   ) AS INTEGER)   -4  ) *8 
                        + Cast(  Case 
                                     When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'F' ) Then 0
                                      When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'E' ) Then 1
                                     When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'D' ) Then 0
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'C' ) Then 2
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'B' ) Then 0
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'A' ) Then 1
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '9' ) Then 0
                                   When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                              For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '8' ) Then 3
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '7' ) Then 0
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '6' ) Then 1
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '5' ) Then 0
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '4' ) Then 2
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '3' ) Then 0
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '2' ) Then 1
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3)
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '1' ) Then 0When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                      For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'F' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                      For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'E' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'D' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'C' ) Then 6
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2)
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'B' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'A' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '9' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '8' ) Then 7
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '7' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '6' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '5' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '4' ) Then 6
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '3' ) Then 4
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '2' ) Then 5
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '1' ) Then 4
                               end 
                         AS INTEGER ) )Else (
                        ( CAST(SubString(h.FORMULE From (Position( '(S' In h.FORMULE ) +2) 
                               For ( Position( ',' In h.FORMULE ) - (Position( '(S' In h.FORMULE ) +2 ))  )      AS INTEGER)   -4) *8 
                        + Case 
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),1) <>0 )  Then 0
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),2) <>0 )  Then 1
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),4) <>0 )  Then 2
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),8) <>0 )  Then 3
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),16) <>0 )  Then 4
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),32) <>0 )  Then 5
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),64) <>0 )  Then 6
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),128) <>0 )  Then 7
                         end )
           End   As Bit_Info
       FROM    SIGNAUX h
    )
    select * 
    from ma_cte
    where Bit_Info ...
    ou
    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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
     
    select *
    from 
      (
       SELECT  h.FORMULE , 
               Case 
                  When Position( ',x',h.FORMULE) <>0 
                     Then ( 
                           (  CAST(SubString(h.FORMULE From (Position( '(S' In h.FORMULE ) +2) 
                             For ( Position( ',' In h.FORMULE ) - (Position( '(S' In h.FORMULE ) +2 ))   ) AS INTEGER)   -4  ) *8 
                        + Cast(  Case 
                                     When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'F' ) Then 0
                                      When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'E' ) Then 1
                                     When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'D' ) Then 0
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'C' ) Then 2
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'B' ) Then 0
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'A' ) Then 1
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '9' ) Then 0
                                   When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                              For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '8' ) Then 3
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '7' ) Then 0
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '6' ) Then 1
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '5' ) Then 0
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '4' ) Then 2
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '3' ) Then 0
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '2' ) Then 1
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3)
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '1' ) Then 0When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                      For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'F' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                      For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'E' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'D' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'C' ) Then 6
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2)
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'B' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'A' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '9' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '8' ) Then 7
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '7' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '6' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '5' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '4' ) Then 6
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '3' ) Then 4
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '2' ) Then 5
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '1' ) Then 4
                               end 
                         AS INTEGER ) )Else (
                        ( CAST(SubString(h.FORMULE From (Position( '(S' In h.FORMULE ) +2) 
                               For ( Position( ',' In h.FORMULE ) - (Position( '(S' In h.FORMULE ) +2 ))  )      AS INTEGER)   -4) *8 
                        + Case 
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),1) <>0 )  Then 0
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),2) <>0 )  Then 1
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),4) <>0 )  Then 2
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),8) <>0 )  Then 3
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),16) <>0 )  Then 4
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),32) <>0 )  Then 5
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),64) <>0 )  Then 6
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),128) <>0 )  Then 7
                         end )
           End   As Bit_Info
       FROM    SIGNAUX h
      ) ma_CTE
    Where Bit_info ...

  9. #9
    Invité de passage
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Décembre 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Décembre 2021
    Messages : 8
    Par défaut
    Citation Envoyé par Michel.Priori Voir le message
    Je comprends que vous voulez simplifier l'écriture de la requête.
    Si c'est bien ça alors il y a 2 écritures possibles :
    • Utiliser une CTE = le mot clé WITH
    • Faire une sous requête nommée


    Sur le principe c'est la même chose.
    La syntaxe avec WITH est plus "maintenable", à mon goût.

    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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
     
    With Ma_cte as (
       SELECT  h.FORMULE , 
               Case 
                  When Position( ',x',h.FORMULE) <>0 
                     Then ( 
                           (  CAST(SubString(h.FORMULE From (Position( '(S' In h.FORMULE ) +2) 
                             For ( Position( ',' In h.FORMULE ) - (Position( '(S' In h.FORMULE ) +2 ))   ) AS INTEGER)   -4  ) *8 
                        + Cast(  Case 
                                     When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'F' ) Then 0
                                      When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'E' ) Then 1
                                     When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'D' ) Then 0
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'C' ) Then 2
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'B' ) Then 0
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'A' ) Then 1
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '9' ) Then 0
                                   When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                              For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '8' ) Then 3
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '7' ) Then 0
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '6' ) Then 1
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '5' ) Then 0
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '4' ) Then 2
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '3' ) Then 0
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '2' ) Then 1
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3)
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '1' ) Then 0When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                      For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'F' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                      For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'E' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'D' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'C' ) Then 6
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2)
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'B' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'A' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '9' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '8' ) Then 7
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '7' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '6' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '5' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '4' ) Then 6
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '3' ) Then 4
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '2' ) Then 5
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '1' ) Then 4
                               end 
                         AS INTEGER ) )Else (
                        ( CAST(SubString(h.FORMULE From (Position( '(S' In h.FORMULE ) +2) 
                               For ( Position( ',' In h.FORMULE ) - (Position( '(S' In h.FORMULE ) +2 ))  )      AS INTEGER)   -4) *8 
                        + Case 
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),1) <>0 )  Then 0
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),2) <>0 )  Then 1
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),4) <>0 )  Then 2
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),8) <>0 )  Then 3
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),16) <>0 )  Then 4
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),32) <>0 )  Then 5
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),64) <>0 )  Then 6
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),128) <>0 )  Then 7
                         end )
           End   As Bit_Info
       FROM    SIGNAUX h
    )
    select * 
    from ma_cte
    where Bit_Info ...

    Bonjour
    Merci pour votre message,
    mais vos propositions ne répondent malheureusement pour moi pas à mon objectif originel, la requête est toujours aussi longue


    en fait c'est la partie du code suivant que je veux remplacer en laissant le reste de la requête

    ce qui correspond à une fonction externe mais je ne souhaite pas utiliser d'UDF

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    (CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER)
    .
    Cordialement

  10. #10
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 739
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 739
    Billets dans le blog
    65
    Par défaut
    Ce que je ne comprends pas, c'est que cette "formule" s'applique bien à une donnée quelconque, il serait certainement plus simple de traiter directement cette donnée !
    AMHA, dans votre cas, l'utilisation d'une UDF (facile à écrire puisque déjà écrite en DELPHI) me semble le plus indiqué. Ne pas vouloir c'est bien mais SQL n'est pas fait pour interpréter ces fameuses formules.

    Quelques exemples de valeurs de la colonne FORMULE et du résultat souhaité seraient quand même bienvenues parce que, perso, je continue à nager

  11. #11
    Modérateur
    Avatar de escartefigue
    Homme Profil pro
    bourreau
    Inscrit en
    Mars 2010
    Messages
    10 703
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : bourreau
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2010
    Messages : 10 703
    Billets dans le blog
    10
    Par défaut
    Si j'ai bien compris, dans la base de données, la colonne "formule" contient non pas une information unitaire, mais un groupe de données délimitées par des séparateurs.
    Du coup il faut utiliser une usine à gaz pour en exploiter la valeur.
    Si c'est bien ça, quelle que soit la solution, elle sera complexe à mettre en oeuvre et à maintenir.
    N'est il pas possible de stocker unitairement les différents attributs de la formule ?

  12. #12
    Invité de passage
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Décembre 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Décembre 2021
    Messages : 8
    Par défaut
    Citation Envoyé par SergioMaster Voir le message
    Ce que je ne comprends pas, c'est que cette "formule" s'applique bien à une donnée quelconque, il serait certainement plus simple de traiter directement cette donnée !
    AMHA, dans votre cas, l'utilisation d'une UDF (facile à écrire puisque déjà écrite en DELPHI) me semble le plus indiqué. Ne pas vouloir c'est bien mais SQL n'est pas fait pour interpréter ces fameuses formules.

    Quelques exemples de valeurs de la colonne FORMULE et du résultat souhaité seraient quand même bienvenues parce que, perso, je continue à nager
    Bonjour et merci de persévérer dans votre aide

    je vais re-fournir les exemples de formule (car ils étaient dans le premier message) et donner le résultat souhaité ( jamais fourni, un oubli fâcheux !)

    Formule : shr(and(S15,112),4) Résultat : bit_info = 92 car (15 -4) * 8 ) ) + 4 ( bit le plus faible de 112)
    Formule : shr(and(S9,28),2) Résultat : bit_Info = 42 car (9 -4) *8)) + 2 ( bit le plus faible de 28)
    Formule : and(S7,x0F) Résultat : bit_info = 24 car (7 -4) *8)) + 0 ( bit le plus faible de 15 # x0F )

    Les données traités par la formule ne sont pas accessibles ( explication ci-dessous)

    La Base de Données défini le fonctionnement d’une application critique devant répondre aux exigences d’un SWAL3,
    Je ne suis pas le concepteur de la Base de Données ,je ne suis qu'un des exploitants de l'application. Je dois donc faire avec !
    Le paramétrage de l'application est réalisé par le téléchargement des données extraites de la base de données à l'aide du logiciel fourni par le concepteur de l'application

    c’est pourquoi toutes les modifications de la Base de Données pour l’évolution de l’application doivent être vérifiées avec une extrême rigueur,
    et la méthodologie des vérifications doit pouvoir être reproduite.

    Le logiciel automatise l’exécution de la batterie de tests de comparaison réalisés à partir des résultats de requête SQL
    sur les différentes Tables constituant la Base de Données N+1 ( objet des évolutions ) et la base de Données (opérationnel) N.
    Cette batterie de tests permet de déterminer le périmètre des modifications effectuées sur la Base de Données lors d’une évolution de celle-ci,
    et constitue le pré-requis de la méthodologie de la vérification statique par delta de la Base de Données;
    des vérifications dynamiques simulées puis en exploitation sont ensuite réalisées sur les données du périmètre des modifications avant son déploiement
    Pour être validé et que le logiciel soit exploitable, les résultats du logiciel doivent donc pouvoir être comparés à ceux des requêtes SQL effectuées avec la méthodologie précédemment validée
    (en l’occurrence Flamerobin pour les interrogations de la Base de Données et Excel pour la comparaison des résultats).

    c’est pourquoi, dans la mesure du possible, les requêtes SQL doivent être privilégiées au sein du logiciel

    Le traitement SQL suivant ( celui du 26/08 ) convient, bien qu'il soit trop long à mon gout
    il n'est qu'une très infime partie de l'ensemble des requêtes SQL réalisée par le logiciel.

    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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
     
    SELECT  h.FORMULE , 
               Case 
                  When Position( ',x',h.FORMULE) <>0 
                     Then ( 
                           (  CAST(SubString(h.FORMULE From (Position( '(S' In h.FORMULE ) +2) 
                             For ( Position( ',' In h.FORMULE ) - (Position( '(S' In h.FORMULE ) +2 ))   ) AS INTEGER)   -4  ) *8 
                        + Cast(  Case 
                                     When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'F' ) Then 0
                                      When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'E' ) Then 1
                                     When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'D' ) Then 0
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'C' ) Then 2
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'B' ) Then 0
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'A' ) Then 1
                                    When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '9' ) Then 0
                                   When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                              For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '8' ) Then 3
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '7' ) Then 0
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '6' ) Then 1
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '5' ) Then 0
                                  When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '4' ) Then 2
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '3' ) Then 0
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '2' ) Then 1
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +3)
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '1' ) Then 0When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                      For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'F' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                      For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'E' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'D' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                             For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'C' ) Then 6
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2)
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'B' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = 'A' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '9' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '8' ) Then 7
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '7' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '6' ) Then 5
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '5' ) Then 4
                                 When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '4' ) Then 6
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '3' ) Then 4
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '2' ) Then 5
                                When ( SubString( h.FORMULE From (Position(',' In h.FORMULE ) +2) 
                                            For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +3 ))  ) = '1' ) Then 4
                               end 
                         AS INTEGER ) )Else (
                        ( CAST(SubString(h.FORMULE From (Position( '(S' In h.FORMULE ) +2) 
                               For ( Position( ',' In h.FORMULE ) - (Position( '(S' In h.FORMULE ) +2 ))  )      AS INTEGER)   -4) *8 
                        + Case 
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),1) <>0 )  Then 0
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),2) <>0 )  Then 1
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),4) <>0 )  Then 2
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                 For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),8) <>0 )  Then 3
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),16) <>0 )  Then 4
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),32) <>0 )  Then 5
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                                For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),64) <>0 )  Then 6
                               When ( Bin_And(CAST(SubString(h.FORMULE From (Position( ',' In h.FORMULE ) +1) 
                                                               For ( Position( ')' In h.FORMULE ) - (Position( ',' In h.FORMULE ) +1 ))  ) AS INTEGER),128) <>0 )  Then 7
                         end )
           End   As Bit_Info
    FROM    SIGNAUX h

    La méthodologie est sans doute lourde mais c'est celle qui a été validée à l'issue d'une longue procédure de validation

    Cordialement

  13. #13
    Invité de passage
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Décembre 2021
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Décembre 2021
    Messages : 8
    Par défaut
    Citation Envoyé par escartefigue Voir le message
    Si j'ai bien compris, dans la base de données, la colonne "formule" contient non pas une information unitaire, mais un groupe de données délimitées par des séparateurs.
    Du coup il faut utiliser une usine à gaz pour en exploiter la valeur.
    Si c'est bien ça, quelle que soit la solution, elle sera complexe à mettre en oeuvre et à maintenir.
    N'est il pas possible de stocker unitairement les différents attributs de la formule ?
    Bonjour et merci pour votre contribution

    La formule fait partie des données transmises à l'application ( voir description dans le précédent message )
    Du fait de la criticité de l'application et n'étant qu'un exploitant de celle-ci je ne peux modifier la Base de Données

    je peux juste développer des outils permettant d'automatiser la réalisation les tests de vérification du périmètre des modifications

    Cordialement

Discussions similaires

  1. [XL-2003] Faire correspondre une colonne avec une autre et copié les données dans la bonne colonne
    Par mairiemeudon dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 01/06/2010, 16h31
  2. [XL-2002] Trouver une valeur specifique dans les colonnes avec une Macro
    Par sergio_gr66 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 30/07/2009, 12h20
  3. Faire la recherche d'un élement dans une colonne avec la fonction match
    Par ckrikri dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 24/11/2008, 12h54
  4. [DataGridViewButtonColumn] Bouton dans une colonne avec une image
    Par aurelien.tournier dans le forum Windows Forms
    Réponses: 1
    Dernier message: 19/11/2007, 12h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo