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

Requêtes et SQL. Discussion :

Numérotation automatique sur une requête union


Sujet :

Requêtes et SQL.

  1. #1
    Membre habitué
    Homme Profil pro
    Contrôleur de Gestion
    Inscrit en
    Mars 2011
    Messages
    314
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Contrôleur de Gestion
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2011
    Messages : 314
    Points : 146
    Points
    146
    Par défaut Numérotation automatique sur une requête union
    Bonjour,

    Je suis aller sur ce tuto pour voir l'incrémentation d'un ID

    J'ai essayé sur ma requête suivante qui est l'union d'une même requête mais dont un champ est changé à chaque select.

    SELECT [Liste Etb & Antennes].Structure, [Base 2011].[N° Pièce], [Base 2011].[N° Ecriture], Month(IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS Mois, IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2)))) AS [Date Comptable], [Base Transco].Nature, [Base 2011].Compte, [Base 2011].[Libellé Compte], [Base 2011].[Journal], [Base 2011].[Libellé Comptable], [Base 2011].Activité, [Base 2011].Antennes, [Base 2011].Débit, [Base 2011].Crédit, [Débit]-[Crédit] AS Solde, IIf([DebutFin] Like "*§*",DateSerial(Val(Right(Left([DebutFin],8),4)),Val(Mid(Left([DebutFin],8),3,2)),Val(Left(Left([DebutFin],8),2))),IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS [Date Début], IIf([DebutFin] Like "*§*",DateSerial(Val(Right(Right([DebutFin],8),4)),Val(Mid(Right([DebutFin],8),3,2)),Val(Left(Right([DebutFin],8),2))),IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS [Date Fin]
    FROM ([Base Transco] INNER JOIN [Base 2011] ON [Base Transco].[NIV 5] = [Base 2011].Compte) INNER JOIN [Liste Etb & Antennes] ON [Base 2011].[N° Structure] = [Liste Etb & Antennes].Num
    WHERE (((Year(IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))))=2011))
    UNION ALL
    SELECT [Liste Etb & Antennes].Structure, [Base 2011].[N° Pièce], [Base 2011].[N° Ecriture], Month(IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS Mois, IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2)))) AS [Date Comptable], [Base Transco].[NIV 3], [Base 2011].Compte, [Base 2011].[Libellé Compte], [Base 2011].[Journal], [Base 2011].[Libellé Comptable], [Base 2011].Activité, [Base 2011].Antennes, [Base 2011].Débit, [Base 2011].Crédit, [Débit]-[Crédit] AS Solde, IIf([DebutFin] Like "*§*",DateSerial(Val(Right(Left([DebutFin],8),4)),Val(Mid(Left([DebutFin],8),3,2)),Val(Left(Left([DebutFin],8),2))),IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS [Date Début], IIf([DebutFin] Like "*§*",DateSerial(Val(Right(Right([DebutFin],8),4)),Val(Mid(Right([DebutFin],8),3,2)),Val(Left(Right([DebutFin],8),2))),IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS [Date Fin]
    FROM ([Base Transco] INNER JOIN [Base 2011] ON [Base Transco].[NIV 5] = [Base 2011].Compte) INNER JOIN [Liste Etb & Antennes] ON [Base 2011].[N° Structure] = [Liste Etb & Antennes].Num
    WHERE (((Year(IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))))=2011))
    UNION ALL
    SELECT [Liste Etb & Antennes].Structure, [Base 2011].[N° Pièce], [Base 2011].[N° Ecriture], Month(IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS Mois, IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2)))) AS [Date Comptable], [Base Transco].[NIV 2], [Base 2011].Compte, [Base 2011].[Libellé Compte], [Base 2011].[Journal], [Base 2011].[Libellé Comptable], [Base 2011].Activité, [Base 2011].Antennes, [Base 2011].Débit, [Base 2011].Crédit, [Débit]-[Crédit] AS Solde, IIf([DebutFin] Like "*§*",DateSerial(Val(Right(Left([DebutFin],8),4)),Val(Mid(Left([DebutFin],8),3,2)),Val(Left(Left([DebutFin],8),2))),IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS [Date Début], IIf([DebutFin] Like "*§*",DateSerial(Val(Right(Right([DebutFin],8),4)),Val(Mid(Right([DebutFin],8),3,2)),Val(Left(Right([DebutFin],8),2))),IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS [Date Fin]
    FROM ([Base Transco] INNER JOIN [Base 2011] ON [Base Transco].[NIV 5] = [Base 2011].Compte) INNER JOIN [Liste Etb & Antennes] ON [Base 2011].[N° Structure] = [Liste Etb & Antennes].Num
    WHERE (((Year(IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))))=2011))
    UNION ALL
    SELECT [Liste Etb & Antennes].Structure, [Base 2011].[N° Pièce], [Base 2011].[N° Ecriture], Month(IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS Mois, IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2)))) AS [Date Comptable], [Base Transco].[NIV 1], [Base 2011].Compte, [Base 2011].[Libellé Compte], [Base 2011].[Journal], [Base 2011].[Libellé Comptable], [Base 2011].Activité, [Base 2011].Antennes, [Base 2011].Débit, [Base 2011].Crédit, [Débit]-[Crédit] AS Solde, IIf([DebutFin] Like "*§*",DateSerial(Val(Right(Left([DebutFin],8),4)),Val(Mid(Left([DebutFin],8),3,2)),Val(Left(Left([DebutFin],8),2))),IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS [Date Début], IIf([DebutFin] Like "*§*",DateSerial(Val(Right(Right([DebutFin],8),4)),Val(Mid(Right([DebutFin],8),3,2)),Val(Left(Right([DebutFin],8),2))),IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS [Date Fin]
    FROM ([Base Transco] INNER JOIN [Base 2011] ON [Base Transco].[NIV 5] = [Base 2011].Compte) INNER JOIN [Liste Etb & Antennes] ON [Base 2011].[N° Structure] = [Liste Etb & Antennes].Num
    WHERE (((Year(IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))))=2011))
    UNION
    ALL SELECT [Liste Etb & Antennes].Structure, [Base 2011].[N° Pièce], [Base 2011].[N° Ecriture], Month(IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS Mois, IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2)))) AS [Date Comptable], [Base Transco].[NIV 0], [Base 2011].Compte, [Base 2011].[Libellé Compte], [Base 2011].[Journal], [Base 2011].[Libellé Comptable], [Base 2011].Activité, [Base 2011].Antennes, [Base 2011].Débit, [Base 2011].Crédit, [Débit]-[Crédit] AS Solde, IIf([DebutFin] Like "*§*",DateSerial(Val(Right(Left([DebutFin],8),4)),Val(Mid(Left([DebutFin],8),3,2)),Val(Left(Left([DebutFin],8),2))),IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS [Date Début], IIf([DebutFin] Like "*§*",DateSerial(Val(Right(Right([DebutFin],8),4)),Val(Mid(Right([DebutFin],8),3,2)),Val(Left(Right([DebutFin],8),2))),IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))) AS [Date Fin]
    FROM ([Base Transco] INNER JOIN [Base 2011] ON [Base Transco].[NIV 5] = [Base 2011].Compte) INNER JOIN [Liste Etb & Antennes] ON [Base 2011].[N° Structure] = [Liste Etb & Antennes].Num
    WHERE (((Year(IIf([Date] Is Not Null,DateSerial(Val(Left([Date],4)),Val(Mid([Date],5,2)),Val(Right([Date],2))),DateSerial(Val(Left(20110101,4)),Val(Mid(20110101,5,2)),Val(Right(20110101,2))))))=2011));
    J'aurais voulu savoir s'il est possible d'affecter une numérotation automatique sur cette requête union.

  2. #2
    Membre habitué
    Homme Profil pro
    Contrôleur de Gestion
    Inscrit en
    Mars 2011
    Messages
    314
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Contrôleur de Gestion
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2011
    Messages : 314
    Points : 146
    Points
    146
    Par défaut
    Cette demande est non avenue car c'est la source que je dois numéroter et non la requête

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 18/03/2014, 14h59
  2. [AC-2007] Requête création de table basée sur une requête union
    Par etoileweb dans le forum Requêtes et SQL.
    Réponses: 1
    Dernier message: 26/08/2011, 20h09
  3. [UNION] - Perte de résultat sur une requête avec UNION
    Par lecail65 dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 01/09/2009, 14h30
  4. Calcul de % sur une requête UNION ALL
    Par lodan dans le forum Langage SQL
    Réponses: 4
    Dernier message: 08/03/2007, 14h20
  5. [Optimisation] Problème sur une requête UNION.
    Par françois62 dans le forum Requêtes
    Réponses: 5
    Dernier message: 28/06/2005, 16h08

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