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

Outils Discussion :

Formatage de requêtes SQL


Sujet :

Outils

  1. #1
    Membre confirmé Avatar de juvamine
    Profil pro
    Chef de projet MOA
    Inscrit en
    Mai 2004
    Messages
    414
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Mai 2004
    Messages : 414
    Points : 502
    Points
    502
    Par défaut Formatage de requêtes SQL
    Bonsoir à tous,

    Ce n'est pas grand chose, et je ne savais pas dans quel forum le mettre. J'ai découvert un site vraiment terrible de formatage sql online
    http://www.sqlinform.com/

    Voilà on lui fournit une requete linéaire toute moche sans indentation ni rien, et il nous ressort un truc sympa comme tout.
    Il existe une version Desktop à télécharger.

    Exemple vite fait, on fournit un truc "moche" comme ça:


    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    select obj.run, obj.camCol, str(obj.field, 3) as field, str(obj.rowc, 6, 1) as rowc, str(obj.colc, 6, 1) as colc, str(dbo.fObj(obj.objId), 4) as id, str(obj.psfMag_g - 0*obj.extinction_g, 6, 3) as g, str(obj.psfMag_r - 0*obj.extinction_r, 6, 3) as r, str(obj.psfMag_i - 0*obj.extinction_i, 6, 3) as i, str(obj.psfMag_z - 0*obj.extinction_z, 6, 3) as z, str(60*distance, 3, 1) as D, dbo.fField(neighborObjId) as nfield, str(dbo.fObj(neighborObjId), 4) as nid,'new' as 'new' from (select obj.objId, run, camCol, field, rowc, colc, psfMag_u, extinction_u, psfMag_g, extinction_g, psfMag_r, extinction_r, psfMag_i, extinction_i, psfMag_z, extinction_z, NN.neighborObjId, NN.distance from photoObj as obj join neighbors as NN on obj.objId = NN.objId where 60*NN.distance between 0 and 15 and NN.mode = 1 and NN.neighborMode = 1 and run = 756 and camCol = 5 and obj.type = 6 and (obj.flags & 0x40006) = 0 and nchild = 0 and obj.psfMag_i < 20 and (g - r between 0.3 and 1.1 and r - i between -0.1 and 0.6) ) as obj join photoObj as nobj on nobj.objId = obj.neighborObjId where nobj.run = obj.run and (abs(obj.psfMag_g - nobj.psfMag_g) < 0.5 or abs(obj.psfMag_r - nobj.psfMag_r) < 0.5 or abs(obj.psfMag_i - nobj.psfMag_i) < 0.5) order by obj.run, obj.camCol, obj.field

    et on ressort ça:


    Code sql : 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
     
    SELECT   obj.run                                               ,
             obj.camCol                                            ,
             str(obj.field, 3)                            AS field ,
             str(obj.rowc, 6, 1)                          AS rowc  ,
             str(obj.colc, 6, 1)                          AS colc  ,
             str(dbo.fObj(obj.objId), 4)                  AS id    ,
             str(obj.psfMag_g - 0*obj.extinction_g, 6, 3) AS g     ,
             str(obj.psfMag_r - 0*obj.extinction_r, 6, 3) AS r     ,
             str(obj.psfMag_i - 0*obj.extinction_i, 6, 3) AS i     ,
             str(obj.psfMag_z - 0*obj.extinction_z, 6, 3) AS z     ,
             str(60           *distance, 3, 1)            AS D     ,
             dbo.fField(neighborObjId)                    AS nfield,
             str(dbo.fObj(neighborObjId), 4)              AS nid   ,
             'new'                                        AS 'new'
    FROM
             (SELECT obj.objId       ,
                     run             ,
                     camCol          ,
                     field           ,
                     rowc            ,
                     colc            ,
                     psfMag_u        ,
                     extinction_u    ,
                     psfMag_g        ,
                     extinction_g    ,
                     psfMag_r        ,
                     extinction_r    ,
                     psfMag_i        ,
                     extinction_i    ,
                     psfMag_z        ,
                     extinction_z    ,
                     NN.neighborObjId,
                     NN.distance
             FROM    photoObj       AS obj
                     JOIN neighbors AS NN
             ON      obj.objId = NN.objId
             WHERE   60*NN.distance BETWEEN 0 AND 15
                 AND NN.mode         = 1
                 AND NN.neighborMode = 1
                 AND run             = 756
                 AND camCol          = 5
                 AND obj.type        = 6
                 AND
                     (
                             obj.flags & 0x40006
                     )
                                  = 0
                 AND nchild       = 0
                 AND obj.psfMag_i < 20
                 AND
                     (
                             g - r BETWEEN 0.3 AND 1.1
                         AND r - i BETWEEN -0.1 AND 0.6
                     )
             )             AS obj
             JOIN photoObj AS nobj
    ON       nobj.objId = obj.neighborObjId
    WHERE    nobj.run   = obj.run
         AND
             (
                      ABS(obj.psfMag_g - nobj.psfMag_g) < 0.5
                   OR ABS(obj.psfMag_r - nobj.psfMag_r) < 0.5
                   OR ABS(obj.psfMag_i - nobj.psfMag_i) < 0.5
             )
    ORDER BY obj.run   ,
             obj.camCol,
             obj.field

    Voilà voilà
    Perso je l'utilise pas mal pour passer mes requete sql directement en chaine de caractère Delphi ou VB...

    C'est de loin le meilleur que j'ai pu tester (ya aussi celui là par exemplehttp://www.dpriver.com/pp/sqlformat.htm ), mais y'a rien à comparer...

    J'espère que ça pourra vous servir un jour

    A+

    juvamine
    Juvamine

  2. #2
    Membre à l'essai
    Inscrit en
    Août 2007
    Messages
    10
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 10
    Points : 16
    Points
    16
    Par défaut
    Merci pour ton lien intéressant.

    Voici une version en ligne sans java si ça intéresse quelqu'un: http://www.dpriver.com/pp/sqlformat.htm

    ps: Je me permet d'ajouter des informations sur ce thème car le topic est très bien placé dans les résultats Google

Discussions similaires

  1. formatage requête sql
    Par xavdeker dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 28/10/2013, 12h41
  2. Réponses: 3
    Dernier message: 23/09/2009, 22h19
  3. Réponses: 2
    Dernier message: 28/02/2007, 14h13
  4. Utilisation de MAX dans une requête SQL
    Par Evil onE dans le forum Langage SQL
    Réponses: 7
    Dernier message: 15/06/2004, 19h38
  5. Requête SQL
    Par Leludo dans le forum Langage SQL
    Réponses: 2
    Dernier message: 17/02/2003, 17h44

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