Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am currently busy on some reporting for a client.

The data for the report is fine there is one problem.
I have data which is being imported to the system via txt documents which is compared to work which is completed at certain stages in my program.

The client has now requested that on the report if the item passes a particular stage more than once in a day the report should only show the first time the item has passed that stage currently my query is

SQL
SELECT DISTINCT
                      dbo.LIstAllStages.Serial, dbo.LIstAllStages.type, dbo.LIstAllStages.type2, dbo.LIstAllStages.Symptom, dbo.LIstAllStages.Comment,
                      dbo.ImportFile.CodeGroup, dbo.Importfile.Code, dbo.ImportFile.comment,
                      dbo.LIstAllStages.WorkCompleted, dbo.LIstAllStages.Stage
FROM         dbo.ImportFile INNER JOIN
                      dbo.LIstAllStages ON dbo.ImportFile.serial COLLATE Latin1_General_CI_AS = dbo.LIstAllStages.Serial
WHERE     dbo.LIstAllStages.Stage = 'SSH'
UNION ALL
SELECT DISTINCT
                      dbo.LIstAllStages.Serial, dbo.LIstAllStages.type, dbo.LIstAllStages.type2, dbo.LIstAllStages.Symptom, dbo.LIstAllStages.Comment,
                      dbo.ImportFile.CodeGroup, dbo.Importfile.Code, dbo.ImportFile.comment,
                      dbo.LIstAllStages.WorkCompleted, dbo.LIstAllStages.Stage
FROM         dbo.ImportFile INNER JOIN
                      dbo.LIstAllStages ON dbo.ImportFile.serial COLLATE Latin1_General_CI_AS = dbo.LIstAllStages.Serial
WHERE     dbo.LIstAllStages.Stage = 'SHS'
 

Please assist in how i could show just the first time the serial will show based on the workcompleted date.
Posted

So you need a flag on your data indicating either when it was uploaded or a BatchID to identify the records from different file uploads. Be careful if you used datetime, as it may be a range of milliseconds in the same upload.

Personally I would have a batch table with an ID and a load time putting the ID ion the transaction records that were loaded per file.
 
Share this answer
 
Take a look at RIGHT JOIN and LEFT JOIN.

What you need to do is get back a result set of some form of unique data for each row. An auto generated column is easiest. And then you pull those rows from the database.
 
Share this answer
 
v2
Comments
isi19 4-Dec-12 1:52am    
Yes i need it to show both stages, problem is if it goes to stage SHS twice within the same day i want it to show the first only

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900