SQL string
This is my query and I am having the same problem.
;with ded as(SELECT
CAT2.CCPsamples.DATASETNUMBER
,cat2.CCPsamples.DEPARTMENT
,cat2.CCPsamples.ACTIVITY_NAME
,cat2.CCPsamples.HAZARDDESCRIPTION
,cat2.CCPsamples.MEASURE
,cat2.CCPsamples.CONTEXTITEM
,dbo.SQLDateTime(cat2.CCPsamples.SAMPLEDATE,
cat2.CCPsamples.SAMPLETIME) AS DateTime
,cat2.CCPsamples.EMPLOYEENO AS [Employee Number]
,CASE WHEN dbo.SQLDate(cat2.CCPsamples.PRODUCTIONDATE)<0 THEN dbo.SQLDate(cat2.CCPsamples.SAMPLEDATE) ELSE dbo.SQLDate(cat2.CCPsamples.PRODUCTIONDATE) END AS PRODUCTIONDATE
,cat2.CCPsamples.SHIFT
,cat2.CCPsamples.SAMPLEVALUE AS Result
,cat2.Personnel.EMPLOYEENAME AS [Employee Name]
,cat2.CCPsamples.SAMPLECOMMENT AS Comments
FROM
cat2.CCPsamples INNER JOIN
cat2.Personnel ON cat2.CCPsamples.EMPLOYEENO = cat2.Personnel.EMPLOYEENO
WHERE
cat2.CCPsamples.HAZARDDESCRIPTION != N'Ambient Temperature'
AND cat2.CCPsamples.DEPARTMENT != N'310'
AND cat2.CCPsamples.DEPARTMENT = N'105'
AND cat2.CCPsamples.HAZARDDESCRIPTION != N'Freezer Area' AND (dbo.SQLDateTime(cat2.CCPsamples.PRODUCTIONDATE, cat2.CCPsamples.SAMPLETIME)
>= @MyStartDate) and (dbo.SQLDateTime(cat2.CCPsamples.PRODUCTIONDATE, cat2.CCPsamples.SAMPLETIME)
<= @MyEndDate))
select *
from ded PIVOT (sum(Result)
FOR Measure IN ([# of Boxes or Combos],[Area],[Date of Tag],[Product Code],[Production Date],[Reason],[Tag #],[Tag Time],[Findings],[Product Disposition],[Release Date],[Release Time],[Rework Code])) AS pvt
ORDER BY DateTime
July 30th, 2012 1:04pm
I have made some changes I know the time is my problem dont know how to fix this. Just trying to get all data on one line per entry.
;with ded as(SELECT CAT2.CCPsamples.DATASETNUMBER
,cat2.CCPsamples.DEPARTMENT
,cat2.CCPsamples.ACTIVITY_NAME
,cat2.CCPsamples.HAZARDDESCRIPTION
,cat2.CCPsamples.MEASURE
,cat2.CCPsamples.CONTEXTITEM
,dbo.SQLDateTime(cat2.CCPsamples.SAMPLEDATE,cat2.CCPsamples.SAMPLETIME) AS Datetime
,cat2.CCPsamples.EMPLOYEENO AS [Employee Number]
,DATEADD (minute, 40 * (DATEDIFF(minute, '20000101', F.[Date/Time]) /1), '20000101') as [Date_Time], CAT2.CCPsamples.DATASETNUMBER AS [Data]
,cat2.CCPsamples.SHIFT
,cat2.CCPsamples.SAMPLEVALUE AS Result
,cat2.Personnel.EMPLOYEENAME AS [Employee Name]
,cat2.CCPsamples.SAMPLECOMMENT AS Comments
FROM CAT2.Personnel INNER JOIN
CAT2.CCPsamples ON CAT2.Personnel.EMPLOYEENO = CAT2.CCPsamples.EMPLOYEENO INNER JOIN
CAT2.Activities ON CAT2.CCPsamples.ACTIVITY_NAME = CAT2.Activities.ACTIVITY_NAME
CROSS APPLY (select dbo.SQLDateTime(CAT2.CCPsamples.PRODUCTIONDATE, CAT2.CCPsamples.SAMPLETIME) AS [Date/Time])F --and cat2.CCPsamples.SAMPLEVALUE
WHERE F.[Date/Time] >= @MyStartDate AND F.[Date/Time] <= @MyEndDate AND F.[Date/Time] <> 0 AND cat2.CCPsamples.DEPARTMENT = 105)
select *
from ded PIVOT (sum(Result)
FOR Measure IN ([# of Boxes or Combos],[Area],[Date of Tag],[Product Code],[Production Date],[Reason],[Tag #],[Tag Time],[Findings],[Product Disposition],[Release Date],[Release Time],[Rework Code])) AS pvt
ORDER BY Datasetnumber
Free Windows Admin Tool Kit Click here and download it now
August 1st, 2012 7:24pm
Hello Spartan734,
Thank you to post your question on TechNet forum.
I reviewed your query string and had concerns that it could return the properly result to us. Based on my experience, the SELECT fields should be <non-pivot fields>, <pivot fields> instead of all fields in the ded, since they are obviously not
the pivot fields or non-pivot fields. For more information, please refer to the following links.
http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx
http://social.technet.microsoft.com/Forums/en-US/sqlreportingservices/thread/bef69334-0c59-42bb-bff1-c654f0441c5a
In addition, please try to remove the detail in the row group, then we can see whether it works for you. If you still encounter the problem, please post out the RDL file you design. Then, we can try to reproduce this issue on our side.
I hope the above information is helpful to you.
Regards,
EdwardEdward Zhu
TechNet Community Support
August 1st, 2012 11:53pm
Can you tell what is the exact problem you're facing and what is your current output? The query seems OK, but perhaps you have field(s) making each row unique. You don't want to include such fields into CTE, otherwise you'll get one row per each unique
column.For every expert, there is an equal and opposite expert. - Becker's Law
My blog
Free Windows Admin Tool Kit Click here and download it now
August 2nd, 2012 1:14am