Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. Company | UID | Approver | Due | InvoiceDate | InvoiceNumber | Vendor | Created
  2. S0009 | USR1 | Random Guy | ... | 20.10.2016 | 123456 | Random Vendor1 | 2016-10-30 10:00:22.000
  3. S0009 | USR1 | Random Guy | ... | 20.10.2016 | 123456 | Random Vendor1 | 2016-10-30 10:00:22.000
  4. S0009 | USR2 | Some Guy | ... | 01.01.2000 | 123456 | Random Vendor1 | 2016-11-01 12:30:16.000
  5. S0009 | USR2 | Some Guy | ... | 01.01.2000 | 123456 | Random Vendor1 | 2016-11-01 12:30:16.000
  6.  
  7. Company | UID | Approver | Due | InvoiceDate | InvoiceNumber | Vendor | Created
  8. S0009 | USR2 | Some Guy | ... | 01.01.2000 | 123456 | Random Vendor1 | 2016-11-01 12:30:16.000
  9.  
  10. SELECT
  11. Upper(WFI.COMPANYID) as Company,
  12. WFI.USERID as UID,
  13. INF.NAME as Approver,
  14. CONVERT(varchar(10),duedatetime,4) as Due,
  15. right(left(Document,20),10) as InvoiceDate,
  16. SUBSTRING(DOCUMENT,22,charindex(' ',RIGHT(DOCUMENT,len(DOCUMENT)-21))) as InvoiceNumber,
  17. Right(document,len(Document)-(20+charindex(' ',RIGHT(DOCUMENT,len(DOCUMENT)-21)))) as Vendor,
  18. wfi.CREATEDDATETIME as Created
  19.  
  20. FROM
  21. [TEST].[tst].[WORKFLOWWORKITEMTABLE] WFI
  22. INNER JOIN [TEST].[tst].[Workflowtrackingstatustable] WFS ON WFI.CORRELATIONID=WFS.CORRELATIONID
  23. INNER JOIN [TEST].[tst].[HCMWORKER] HCM on WFI.USERID=HCM.PERSONNELNUMBER
  24. INNER JOIN [TEST].[tst].[DIRPERSONNAME] DPN ON DPN.PERSON=HCM.PERSON
  25. INNER JOIN [TEST].[tst].[LEDGERJOURNALTABLE] LJT ON WFI.REFRECID = LJT.RECID
  26. INNER JOIN [TEST].[tst].[USERINFO] INF ON WFI.USERID = INF.ID
  27.  
  28. WHERE
  29. DATASOURCENAME Like 'Ledgerjourna%'
  30. AND Datediff(day,Duedatetime,getdate())>3
  31. AND WFS.DOCUMENTTYPE='Special'
  32.  
  33. ORDER BY
  34. WFI.COMPANYID asc
  35.  
  36. SELECT main.* FROM
  37. (
  38. SELECT
  39. Upper(WFI.COMPANYID) as Company
  40. WFI.USERID as UID,
  41. INF.NAME as Approver,
  42. CONVERT(varchar(10),duedatetime,4) as Due,
  43. right(left(Document,20),10) as InvoiceDate,
  44. SUBSTRING(DOCUMENT,22,charindex(' ',RIGHT(DOCUMENT,len(DOCUMENT)-21))) as InvoiceNumber,
  45. Right(document,len(Document)-(20+charindex(' ',RIGHT(DOCUMENT,len(DOCUMENT)-21)))) as Vendor,
  46. wfi.CREATEDDATETIME as Created,
  47. --Added RowNumber Function Below
  48. ROW_NUMBER() OVER (PARTITION BY **InsertYourKeyToAUniqueRecordHere** ORDER BY wfi.CREATEDDATETIME DESC) AS ROWNUM
  49.  
  50. FROM
  51. [TEST].[tst].[WORKFLOWWORKITEMTABLE] WFI
  52. INNER JOIN [TEST].[tst].[Workflowtrackingstatustable] WFS ON WFI.CORRELATIONID=WFS.CORRELATIONID
  53. INNER JOIN [TEST].[tst].[HCMWORKER] HCM on WFI.USERID=HCM.PERSONNELNUMBER
  54. INNER JOIN [TEST].[tst].[DIRPERSONNAME] DPN ON DPN.PERSON=HCM.PERSON
  55. INNER JOIN [TEST].[tst].[LEDGERJOURNALTABLE] LJT ON WFI.REFRECID = LJT.RECID
  56. INNER JOIN [TEST].[tst].[USERINFO] INF ON WFI.USERID = INF.ID
  57.  
  58. WHERE
  59. DATASOURCENAME Like 'Ledgerjourna%'
  60. AND Datediff(day,Duedatetime,getdate())>3
  61. AND WFS.DOCUMENTTYPE='Special'
  62.  
  63. ORDER BY
  64. )main
  65.  
  66. WHERE main.ROWNUM =1 --Add this clause to only return the first record
  67. main.Company asc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement