Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. USE [Procedure]
  2. GO
  3.  
  4. /****** Object: View [dbo].[vTender_OOS] Script Date: 12.02.2016 12:47:07 ******/
  5. DROP VIEW [dbo].[vTender_OOS]
  6. GO
  7.  
  8. /****** Object: View [dbo].[vTender_OOS] Script Date: 12.02.2016 12:47:07 ******/
  9. SET ANSI_NULLS ON
  10. GO
  11.  
  12. SET QUOTED_IDENTIFIER ON
  13. GO
  14.  
  15.  
  16.  
  17.  
  18.  
  19. CREATE VIEW [dbo].[vTender_OOS]
  20. AS
  21. SELECT
  22. ut.task_id AS [id]
  23. ,ut.id AS [mytenderid]
  24. ,ut.[guid] AS [guid]
  25. ,ut.purchaseId AS [PurchaseID]
  26. ,ust.sort_field [Status]
  27. ,ut.[bossId] AS [bossid]
  28. ,ut.ownerId AS [OwnerId]
  29. ,CONVERT(DATETIME, ut.insertDate) AS [InsertDate]
  30. ,CONVERT(DATETIME, ut.lastActivityDate) AS [lastActivityDate]
  31. ,ut.reportId AS [reportId]
  32. ,ISNULL(ut.supViser, '') AS [supViser]
  33. ,COALESCE(lt.subject, nt.orderName, '') AS [Name]
  34. ,ISNULL(nt.OrganizerName, '') AS [Organizer]
  35. ,ISNULL(STUFF((SELECT
  36. [Procedure].dbo.strconcat(DISTINCT '|| ' + CUST.fullName)
  37. FROM
  38. OOS.dbo.OrganizationTable CUST WITH (NOLOCK)
  39. INNER JOIN OOS.dbo.CustomerRequirementTable CRT WITH (NOLOCK) ON CUST.GUID = CRT.customer
  40. WHERE
  41. CRT.customerRequirementGUIDLink = lt.GUID
  42. ), 1, 3, ''), '') AS [Customer]
  43. ,ISNULL(nt.Amount, 0) AS [GarantyAmount]
  44. ,ISNULL(nt.Amount_con, 0) AS [GuaranteeAmountCon]
  45. ,ISNULL(NPT.deliveryPlace, '') AS [DeliveryPlace]
  46. ,ISNULL(ctp.price, 0) AS resultSum
  47. ,--winner_value
  48. ISNULL(nt.notificationNumber, '') AS [NotificationNumber]
  49. ,COALESCE((SELECT
  50. SUM(CRT1.maxPrice)
  51. FROM
  52. OOS.dbo.CustomerRequirementTable CRT1 WITH (NOLOCK)
  53. WHERE
  54. CRT1.customerRequirementGUIDLink = lt.GUID
  55. ), lt.maxPrice, 0) AS [PurchaseStartPrice]
  56. ,ISNULL(nct.HoldingDate, '1970-01-01') AS [AuctionDate]
  57. ,ISNULL(rrt.Sort_field, 0) AS [RegionID]
  58. ,ISNULL(nt.StartDate, '1970-01-01') AS [DateStart]
  59. ,ISNULL(nt.EndDate, '1970-01-01') AS [DateFinish]
  60. ,0 AS [ex_DateStart]
  61. ,0 AS [ex_DateFinish]
  62. ,ISNULL(nt.href, '') AS [SourceLink]
  63. ,ISNULL(rctt.Sort_field, 0) AS [ContractTypeID]
  64. ,ISNULL(refCur.sort_field, 12000) AS [CurrencyID]
  65. ,ISNULL(rept.ID, 0) AS PlatformID
  66. ,ISNULL(crmreg.sort_field, 0) AS userregion_id
  67. ,ISNULL(crmmreg.sort_field, 0) AS usermregion_id
  68. ,COALESCE(opf.alias + ' ', '') + ISNULL(cpt.[name], '') winner_name
  69. ,ISNULL(ut.source, 0) AS FilterID
  70. FROM
  71. [mt].[UserTasks] ut
  72. LEFT JOIN [mt].[UsersTasksStatuses] ust ON ut.status = ust.id
  73. LEFT JOIN OOS.dbo.LotTable AS lt WITH (NOLOCK) ON lt.GUID = (SELECT TOP 1
  74. LotGUID
  75. FROM
  76. OOS.dbo.lotHashTable WITH (NOLOCK)
  77. WHERE
  78. Hash = ut.lotHash
  79. ORDER BY
  80. ID DESC
  81. )
  82. LEFT JOIN OOS.dbo.NotificationTable nt WITH (NOLOCK) ON nt.ID = ut.purchaseId
  83. LEFT JOIN Dicts.dbo.RefCurrencyTable AS refCur WITH (NOLOCK) ON refCur.GUID = nt.Currency
  84. LEFT JOIN OOS.dbo.NotificationPlacementTable NPT WITH (NOLOCK) ON NPT.notificationPlacementGUIDLink = nt.GUID
  85. LEFT JOIN OOS.dbo.NotificationCommissionTable nct WITH (NOLOCK) ON nct.GUID = nt.notificationCommission
  86. LEFT JOIN Dicts.dbo.RefRegionTable AS rrt WITH (NOLOCK) ON nt.OrganizerRegionGuid = rrt.GUID
  87. LEFT JOIN Dicts.dbo.RefContractTypeTable AS rctt WITH (NOLOCK) ON nt.ContractType = rctt.GUID
  88. LEFT JOIN OOS.dbo.RefEPTable rept WITH (NOLOCK) ON rept.GUID = nt.EP AND rept.GUID != '354B82CB-F6FF-4220-826F-9211C17BD3AF'
  89. /*региоы и макро регионы*/
  90. LEFT JOIN [mt].[UserOrg] cuo ON cuo.usrId = ut.ownerId
  91. LEFT JOIN [mt].[UsersRegions] ur WITH (NOLOCK) ON ur.user_id = ut.ownerId
  92. LEFT JOIN [mt].[RefRegionTable] crmreg WITH (NOLOCK) ON crmreg.id = [region_id]
  93. LEFT JOIN [mt].[RefRegionsMacroRegion] rmr WITH (NOLOCK) ON rmr.org_guid = cuo.orgGuid AND rmr.region_id = ur.region_id
  94. LEFT JOIN [mt].[RefMacroRegionTable] crmmreg WITH (NOLOCK) ON crmmreg.id = rmr.maro_region_id
  95. /*победитель*/
  96. LEFT JOIN [mt].[TendersParticipants] ctp WITH (NOLOCK) ON ctp.tender_id = ut.task_id AND ctp.winner = 1
  97. LEFT JOIN [mt].[ParticipantTable] cpt WITH (NOLOCK) ON cpt.part_id = ctp.participant_id
  98. LEFT JOIN [mt].[ParticipantOPF] opf WITH (NOLOCK) ON cpt.opf_id = opf.id
  99. WHERE
  100. ut.reportId = 32
  101.  
  102.  
  103.  
  104.  
  105. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement