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

MS SQL Server Discussion :

Ajout colonne identification d'information [2012]


Sujet :

MS SQL Server

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Novembre 2008
    Messages : 38
    Points : 43
    Points
    43
    Par défaut Ajout colonne identification d'information
    Bonjour à tous et merci à l'avance de votre aide. Pour ceux qui serait familier, j'interroge les BD propriétaires de Project Server 2013.

    Je fais face à un problème avec ma requête. Ma requête doit servir à identifier deux types d'information soit des $ et de JP. Dans la requête ci-dessous, je retourne les sommes des $ et des JP (assignment...work ou assignment...cost). C'est ici que la bas blesse. Je dois réussir à créer une nouvelle colonne, nommons la Type, qui permettra de distinguer ce qui est $ de ce qui est JP. Mais je n'y parviens pas.

    J'ai tenté de tronquer cette requête en deux pour ajouter une colone DataType=JP ou DataType=$ et ensuite les joindre par une jointure ou un union mais sans bon résultats. À noter que la requête finale doit être exécuter dans une vue ou par Excel, donc l'utilisation des table temporaires n'est pas possible à moins que je ne me trompe.

    Alors voilà le topo. Merci encore pour vos cerveaux


    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
    SELECT        
    _P.ProjectName COLLATE Latin1_General_CI_AS as ProjectName, 
    _P.[CF Nom] AS [Titre du projet], 
    _P.[CF Numéro], 
    _P.[CF Directeur], 
    _P.[CF Chef], 
    _P.[CF Phase], 
    ISNULL(_R.[CF Type], 'N/D') AS [CF Type], 
    CASE 
    	WHEN (_R.[CF Type] = 'Interne' AND AUV.[CF CR ressource_R] IS NOT NULL) THEN ISNULL(LEFT(RIGHT(AUV.[CF CR ressource_R], 8), 3), 'N/D') 
    	WHEN (_R.[CF Type] = 'Externe' AND AUV.[CF CR ressource_R] IS NOT NULL)  THEN ISNULL(LEFT(RIGHT(AUV.[CF CR ressource_R], 8), 3), 'N/D') 
    	ELSE ISNULL(LEFT(RIGHT(AUV.[CF CR affectation_T], 8), 3), 'N/D') 
    END AS [Catégorie ressource], 
    CASE 
    	WHEN YEAR(ABD.TimeByDay) = YEAR(GETDATE()) THEN ('Année ' + CAST((YEAR(GETDATE())) AS nvarchar(4))) 
    	WHEN YEAR(ABD.TimeByDay) = (YEAR(GETDATE()) + 1) THEN ('Année ' + CAST((YEAR(GETDATE()) + 1) AS nvarchar(4))) 
    	WHEN YEAR(ABD.TimeByDay) = (YEAR(GETDATE()) + 2) THEN ('Année ' + CAST((YEAR(GETDATE()) + 2) AS nvarchar(4))) 
    	WHEN YEAR(ABD.TimeByDay) > (YEAR(GETDATE()) + 2)  THEN 'Années futures' 
    	ELSE 'Années passées' 
    END AS Période, 
    [Année]= (CAST(YEAR(ABD.TimeByDay)AS nvarchar(4))),
    ISNULL(SUM(ABD.AssignmentActualCost), 0) AS [A_Coût réalisation], 
    ISNULL(SUM(ABD.AssignmentRemainingCost), 0) AS [A_Coût restant], 
    ISNULL(SUM(ABD.AssignmentBaseline10Cost), 0) AS [A_Coût autorisé], 
    ISNULL(SUM(ABD.AssignmentActualCost), 0) + ISNULL(SUM(ABD.AssignmentRemainingCost), 0) AS [A_Coût total], 
    ISNULL(SUM(ABD.AssignmentBaseline10Cost), 0) - (ISNULL(SUM(ABD.AssignmentActualCost), 0) + ISNULL(SUM(ABD.AssignmentRemainingCost), 0)) AS [A_Écart Coût], 
    ISNULL(SUM(ABD.AssignmentActualWork), 0) / 7 AS [A_Travail réalisation], 
    ISNULL(SUM(ABD.AssignmentRemainingWork), 0) / 7 AS [A_Travail restant], 
    ISNULL(SUM(ABD.AssignmentBaseline10Work), 0) / 7 AS [A_Travail autorisé], 
    (ISNULL(SUM(ABD.AssignmentActualWork), 0) + ISNULL(SUM(ABD.AssignmentRemainingWork), 0)) / 7 AS [A_Travail total], 
    (ISNULL(SUM(ABD.AssignmentBaseline10Work), 0) - (ISNULL(SUM(ABD.AssignmentActualWork), 0) + ISNULL(SUM(ABD.AssignmentRemainingWork), 0)))/ 7 AS [A_Écart travail],
    _P.ProjectUID
     
    FROM            dbo.MSP_EpmAssignmentByDay_UserView AS ABD WITH (nolock) 
    LEFT OUTER JOIN dbo.MSP_EpmAssignment_UserView AS AUV WITH (nolock) ON ABD.AssignmentUID = AUV.AssignmentUID 
    LEFT OUTER JOIN dbo.MSP_EpmAssignment AS _A WITH (nolock) ON ABD.AssignmentUID = _A.AssignmentUID 
    LEFT OUTER JOIN dbo.MSP_EpmTask_UserView AS _T WITH (nolock) ON ABD.ProjectUID = _T.ProjectUID AND ABD.TaskUID = _T.TaskUID 
    LEFT OUTER JOIN dbo.MSP_EpmProject_UserView AS _P WITH (nolock) ON _A.ProjectUID = _P.ProjectUID 
    LEFT OUTER JOIN (SELECT DISTINCT ResourceName COLLATE Latin1_General_CI_AS AS Expr1, 
    								 [CF Type], 
    								 ResourceUID, 
    								 ResourceIsGeneric
                     FROM dbo.MSP_EpmResource_UserView AS R WITH (nolock)
    				 ) AS _R ON AUV.ResourceUID = _R.ResourceUID
     
    GROUP BY 
    ABD.TimeByDay, 
    _P.ProjectName COLLATE Latin1_General_CI_AS, 
    _P.ProjectUID,
    _P.[CF Nom], 
    _P.[CF Numéro], 
    _P.[CF Directeur], 
    _P.[CF Chef], 
    _P.[CF Phase], 
    _R.[CF Type], 
    AUV.[CF CR affectation_T], 
    AUV.[CF CR ressource_R]

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Novembre 2008
    Messages : 38
    Points : 43
    Points
    43
    Par défaut Problème résolu
    J'ai finalement résolu le problème en utilisant un UNION.

    Solution finale :

    je créer une vue avec ma première requête et ensuite je l'interroge avec la requête suivante.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    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
    SELECT '$' as [DataType],
    ProjectName,
    Période,
    Année,
    CASE WHEN Année < YEAR(GETDATE()) THEN (SUM([A_Coût total])) END AS [Total années antérieures],
    CASE WHEN Année = YEAR(GETDATE()) THEN (SUM([A_Coût réalisation])) END AS [Réel année en cours], 
    CASE WHEN Année = YEAR(GETDATE()) THEN (SUM([A_Coût restant])) END AS [À venir année en cours],
    CASE WHEN Année = YEAR(GETDATE()) THEN (SUM([A_Coût total])) END AS [Projeté années en cours],
    CASE WHEN Année = (YEAR(GETDATE())+1) THEN (SUM([A_Coût total])) END AS [Projeté 1 an],
    CASE WHEN Année = (YEAR(GETDATE())+2) THEN (SUM([A_Coût total])) END AS [Projeté 2 ans],
    CASE WHEN Année > (YEAR(GETDATE())+2) THEN (SUM([A_Coût total])) END AS [Projeté plus de 2 ans],
    [Titre du projet],
    [CF Numéro],
    [CF Directeur],
    [CF Chef],
    [CF Phase],
    [CF Type],
    [Catégorie ressource],
    [ProjectUID]
     
    FROM [dbo].[FicheFinanciere] 
     
    GROUP BY 
    ProjectName,
    ProjectUID,
    Période,
    Année,
    [Titre du projet],
    [CF Numéro],
    [CF Directeur],
    [CF Chef],
    [CF Phase],
    [CF Type],
    [Catégorie ressource]
     
    UNION 
     
    SELECT 'JP' as [DataType],
    ProjectName,
    Période,
    Année,
    CASE WHEN Année < YEAR(GETDATE()) THEN (SUM([A_Travail total])) END AS [Total années antérieures],
    CASE WHEN Année = YEAR(GETDATE()) THEN (SUM([A_Travail réalisation])) END AS [Réel année en cours], 
    CASE WHEN Année = YEAR(GETDATE()) THEN (SUM([A_Travail restant])) END AS [À venir année en cours],
    CASE WHEN Année = YEAR(GETDATE()) THEN (SUM([A_Travail total])) END AS [Projeté années en cours],
    CASE WHEN Année = (YEAR(GETDATE())+1) THEN (SUM([A_Travail total])) END AS [Projeté 1 an],
    CASE WHEN Année = (YEAR(GETDATE())+2) THEN (SUM([A_Travail total])) END AS [Projeté 2 ans],
    CASE WHEN Année > (YEAR(GETDATE())+2) THEN (SUM([A_Travail total])) END AS [Projeté plus de 2 ans],
    [Titre du projet],
    [CF Numéro],
    [CF Directeur],
    [CF Chef],
    [CF Phase],
    [CF Type],
    [Catégorie ressource],
    [ProjectUID]
     
    FROM [dbo].[FicheFinanciere] 
     
    GROUP BY 
    ProjectName,
    ProjectUID,
    Période,
    Année,
    [Titre du projet],
    [CF Numéro],
    [CF Directeur],
    [CF Chef],
    [CF Phase],
    [CF Type],
    [Catégorie ressource]
    En souhaitant que ce soit utile à d'autre.

    Merci d'avoir lu mon monologue

    Toutes propositions d'améliorations seront considérées.

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

Discussions similaires

  1. [DOM] Modification tableau plus ajout colonne.
    Par Shandler dans le forum Général JavaScript
    Réponses: 13
    Dernier message: 03/12/2007, 12h22
  2. Ajout colonne ACCESS
    Par Inho69 dans le forum Requêtes et SQL.
    Réponses: 3
    Dernier message: 18/07/2007, 13h22
  3. [colonne] Récupérer des informations
    Par cysboy dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 06/06/2007, 10h07
  4. Ajout colonnes Dans Table
    Par cjacquel dans le forum Access
    Réponses: 3
    Dernier message: 11/12/2006, 21h29
  5. [VBA] Ajout colonne dans recordset
    Par le_niak dans le forum Access
    Réponses: 25
    Dernier message: 31/07/2006, 11h35

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