Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
wided
Posting Yak Master
218 Posts |
Posted - 2014-01-02 : 11:49:33
|
helloI have an application that worked well for sql 2000I use (= *) here is my request :select t0.matricule , t1.semaine , t1.rubrique, ROW_NUMBER ( ) OVER ( PARTITION BY t0.matricule , t1.semaine ORDER BY t0.matricule , t1.semaine ASC) AS RowNumber, Sum ( isnull ( NbrHeure , 0) ) as NbrHeurefrom H53FT_IHMParamsIntegrationEnColonne ( '20130101 ', '20130115 ') t1,H11_Employe t0, t2 H53_MvtPresenceWheret0.Matricule = t2.matriculeand t1.rubrique * = t2.rubriqueand t1.semaine = t2.numsemaineand t0.Matricule = '1001 'Between DateMvt and '20130101 'and '20130115 'Here is the result of the first query is good :1001 1 98 1 4801001 1 99 2 01001 1 100 3 15611001 1 107 4 15611001 1 108 5 01001 1 120 6 01001 1 124 7 01001 1 125 8 1941001 1 500 9 01001 2 98 1 01001 2 99 2 01001 2 100 3 21911001 2 107 4 21911001 2 108 5 9741001 2 120 6 01001 2 124 7 01001 2 125 8 2981001 2 500 9 960with the 2008 version , I use the instructions join instead of * = , only I did not find the same resulthere is the new application :select t0.matricule , t1.semaine , t1.rubrique, ROW_NUMBER ( ) OVER ( PARTITION BY t0.matricule , t1.semaine ORDER BY t0.matricule , t1.semaine ASC) AS RowNumber, Sum ( isnull ( NbrHeure , 0) ) as NbrHeurefrom H53FT_IHMParamsIntegrationEnColonne ( '20130101 ', '20130115 ') t1 left outer join t2 H53_MvtPresence we t1.rubrique = t2.rubrique and t1.semaine = t2.numsemaine join H11_Employe t0.Matricule = t0 we t2.matriculeand t0.Matricule = '1001 'Between DateMvt and '20130101 'and '20130115 'group by t0.matricule , t1.semaine , t1.rubriqueHere is the result of the second query :1001 1 98 1 4801001 1 100 2 15611001 1 107 3 15611001 1 125 4 1941001 2 100 1 21911001 2 107 2 21911001 2 108 3 9741001 2 125 4 2981001 2 500 5 960I need to find all the items ( 98,99,100 ........) are in the following H53FT_IHMParamsIntegrationEnColonne function and are not in the table H53_MvtPresenceI need your help |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-02 : 12:56:30
|
try thisselect t0.matricule , t1.semaine , t1.rubrique, ROW_NUMBER ( ) OVER ( PARTITION BY t0.matricule , t1.semaine ORDER BY t0.matricule , t1.semaine ASC) AS RowNumber, Sum ( isnull ( NbrHeure , 0) ) as NbrHeurefrom H53FT_IHMParamsIntegrationEnColonne ( '20130101 ', '20130115 ') t1left join H53_MvtPresence t2 on t1.rubrique = t2.rubriqueand t1.semaine = t2.numsemaineleft join H11_Employe t0on t0.Matricule = t2.matricule and t0.Matricule = '1001 'where DateMvt Between '20130101' and '20130115' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
wided
Posting Yak Master
218 Posts |
Posted - 2014-01-03 : 06:45:06
|
thanks Visakh16it's ok for rubrique (98,99....)but its not ok for matricule (first colonne = null)NULL 1 98 1 2395NULL 1 100 2 12054NULL 1 107 3 12054NULL 1 108 4 2909NULL 1 120 5 337NULL 1 124 6 305NULL 1 125 7 430NULL 1 500 8 2100NULL 2 98 1 6900NULL 2 99 2 300NULL 2 100 3 16933NULL 2 107 4 17456NULL 2 108 5 4365NULL 2 120 6 831NULL 2 124 7 362NULL 2 125 8 740NULL 2 500 9 31801001 1 98 1 4801001 1 100 2 15611001 1 107 3 15611001 1 125 4 1941001 2 100 1 21911001 2 107 2 21911001 2 108 3 9741001 2 125 4 2981001 2 500 5 960 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-03 : 07:36:44
|
Are you telling you dont need them?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
wided
Posting Yak Master
218 Posts |
Posted - 2014-01-06 : 02:53:20
|
I need Anyone becaufe in the following query, I need to display data in columnsNumsemaine rubrique98 rubrique99 Rubriqu 100 ....1 value98 value99 value100 ...23My second request is ready and the result depends on the first query |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-06 : 06:42:52
|
So for those NULL values whats the value you need to see instead in output?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
wided
Posting Yak Master
218 Posts |
Posted - 2014-01-06 : 07:58:53
|
employees who do not have a listing for 98 or 99 for example, so the value of last columns must be equal to 0)for my example: 1001 employee has no value in the section 99 (column 3), weekly (column 2), he must give me this1001 1 99 01001 1 100 5021001 2 99 01001 2 100 636 |
|
|
wided
Posting Yak Master
218 Posts |
Posted - 2014-01-06 : 08:02:30
|
section 99 are in the function "H53FT_IHMParamsIntegrationEnColonne" but not in table H53_MvtPresence I can do without the table H11_Employe |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2014-01-06 : 08:21:25
|
1. ROW_NUMBER() does not work in SQL20002. Your original query has other syntax problems.Try something like:SELECT t0.matricule , t1.semaine , t1.rubrique ,ROW_NUMBER() OVER (PARTITION BY t0.matricule, t1.semaine ORDER BY t0.matricule, t1.semaine) AS RowNumber ,SUM(ISNULL(NbrHeure , 0)) AS NbrHeureFROM H11_Employe t0 JOIN H53_MvtPresence t2 ON t0.Matricule = t2.matricule RIGHT JOIN H53FT_IHMParamsIntegrationEnColonne('20130101', '20130115') t1 ON t2.rubrique = t1.rubrique AND t2.numsemaine = t1.semaineWHERE t2.numsemaine = t1.semaine AND t0.Matricule = '1001' AND DateMvt BETWEEN '20130101' AND '20130115' |
|
|
wided
Posting Yak Master
218 Posts |
Posted - 2014-01-06 : 08:44:28
|
Ifor, this is the result1001 1 98 1 4801001 1 100 2 15611001 1 107 3 15611001 1 125 4 1941001 2 100 1 21911001 2 107 2 21911001 2 108 3 9741001 2 125 4 2981001 2 500 5 960section 99 does not appear1001 1 99 2 0.... |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2014-01-06 : 08:49:51
|
What table is DateMvt in? |
|
|
wided
Posting Yak Master
218 Posts |
Posted - 2014-01-06 : 09:35:10
|
from table H53_MvtPresence |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2014-01-06 : 10:11:27
|
Try:SELECT t0.matricule , t1.semaine , t1.rubrique ,ROW_NUMBER() OVER (PARTITION BY t0.matricule, t1.semaine ORDER BY t0.matricule, t1.semaine) AS RowNumber ,SUM(ISNULL(NbrHeure , 0)) AS NbrHeureFROM H11_Employe t0 JOIN H53_MvtPresence t2 ON t0.Matricule = t2.matricule AND t0.Matricule = '1001' AND t2.DateMvt BETWEEN '20130101' AND '20130115' RIGHT JOIN H53FT_IHMParamsIntegrationEnColonne('20130101', '20130115') t1 ON t2.rubrique = t1.rubrique AND t2.numsemaine = t1.semaineWHERE t2.numsemaine = t1.semaine If that does not work you will need to post some consumable test data along with the expected results. |
|
|
wided
Posting Yak Master
218 Posts |
Posted - 2014-01-06 : 11:04:10
|
I will simplify my problemH53FT_IHMParamsIntegrationEnColonne the function return the following line :9899100107125500H53_MvtPresence table contains :Employé Week Section Number 1001 1 100 3251001 1 107 4601001 1 125 2551001 2 99 4141001 2 107 8581001 2 125 747I need a list of numbers grouped by week , by topic.If the items are not included in the table H53_MvtPresence , they appear with the value 0The result I would like to have1001 1 98 01001 1 99 01001 1 100 3251001 1 107 4601001 1 125 2551001 1 500 01001 2 98 01001 2 99 4141001 2 100 01001 2 107 8581001 2 125 7471001 2 500 0H11_employe the table is not necessarythe link with the week is not necessary |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2014-01-06 : 12:49:24
|
[code]-- *** Test Data in Consumable Format ***-- You should provide thisCREATE TABLE #H53FT_IHMParamsIntegrationEnColonne( Section int NOT NULL);INSERT INTO #H53FT_IHMParamsIntegrationEnColonneVALUES (98),(99),(100),(107),(125),(500);CREATE TABLE #H53_MvtPresence( Employé int NOT NULL ,[Week] tinyint NOT NULL ,Section int NOT NULL ,Number int NOT NULL);INSERT INTO #H53_MvtPresenceVALUES (1001, 1, 100, 325) ,(1001, 1, 107, 460) ,(1001, 1, 125, 255) ,(1001, 2, 99, 414) ,(1001, 2, 107, 858) ,(1001, 2, 125, 747);-- *** End Test Data in Consumable Format ***WITH EmployéWeekAS( SELECT DISTINCT Employé, [Week] FROM #H53_MvtPresence)SELECT EW.Employé, EW.[Week], C.Section ,COALESCE(SUM(P.Number), 0) AS NumberFROM EmployéWeek EW CROSS JOIN #H53FT_IHMParamsIntegrationEnColonne C LEFT JOIN #H53_MvtPresence P ON EW.Employé = P.Employé AND EW.[Week] = P.[Week] AND C.Section = P.SectionGROUP BY EW.Employé, EW.[Week], C.SectionORDER BY Employé, [Week], Section;[/code] |
|
|
|
|
|
|
|