我有一个非常复杂的表格,我们无法修改表格,因此我根据之前的问题收到的一些帮助制作了一个评分系统。
我确实想要一个View,所以我可以通过SQL Agent将它导入另一个'Data-cube'数据库,其结果可以很容易地报告,但因为我有一个“DECLARE”功能,所以这不能成为一个视图。
如何将结果导入其当前状态的另一个数据库,或者我是否需要更改其工作方式?
这是迄今为止的代码(有些需要case语句,因为如果该作业不需要它们可以在提交的表单上跳过它们,那么它们将返回为NULL):
DECLARE @Translate AS TABLE
(
string varchar(17),
number int
)
INSERT INTO @Translate VALUES
('Checked Ok', 0),
('Rectified On-Site', 5),
('Failed', 5),
('N/A', 0)
SELECT [form].[Name],
[form].[aField875] AS [WorkOrder],
[form].[aField874] AS [Address],
[form].[TimeTag1] AS [Started],
[form].[TimeTag2] AS [Submitted],
DATEDIFF(MINUTE,[form].[TimeTag1],[form].[TimeTag2]) AS [TimeDifference],
(100 - [Form].[Field46] - [Form].[Field2] - [Form].[Field4] - [Form].[Field5]
- [Form].[Field7] - [Form].[Field6] - [Form].[Field12] - [Form].[Field11] - [Form].[Field10] --Risk Assessments & Method Statements
- [Form].[Field17] - [Form].[Field16] - [Form].[Field15] - [Form].[Field14] -- Training/Certs
- [Form].[Field23] - [Form].[Field22] - [Form].[Field21] - [Form].[Field20] -- P.P.E
- [Form].[Field28] - [Form].[Field27] - [Form].[Field26] - [Form].[Field25] - [Form].[Field717] -- Emergency Preparedness
- [Form].[Field34] - [Form].[Field33] - [Form].[Field32] - [Form].[Field31] - [Form].[Field38] - [Form].[Field30] - [Form].[Field37] -- Plant and Vehicles
- [Form].[Field36] - [Form].[Field35] - [Form].[Field42] - [Form].[Field41] - [Form].[Field40] - [Form].[Field39] - [Form].[Field43] -- Plant and Vehicles
- [Form].[Field45] - [Form].[Field50] - [Form].[Field49] - [Form].[Field48] - [Form].[Field47] - [Form].[Field53] - [Form].[Field52] - [Form].[Field56] - [Form].[Field57] - [Form].[Field58] -- Tools and Equipment
- [Form].[Field54] - [Form].[Field62] - [Form].[Field61] - [Form].[Field60] - [Form].[Field59] -- COSHH
- [Form].[Field67] - [Form].[Field66] - [Form].[Field65] - [Form].[Field64] - [Form].[Field68] -- Customer
- [Form].[Field266] - [Form].[Field265] - [Form].[Field271] - [Form].[Field264] - [Form].[Field263] - [Form].[Field262] - [Form].[Field261] -- Excavations, Safe digging and Overhead lines
- [Form].[Field260] - [Form].[Field269] - [Form].[Field268] - [Form].[Field267] - [Form].[Field274] - [Form].[Field273] - [Form].[Field272] - [Form].[Field270] -- Excavations, Safe digging and Overhead lines
- [Form].[Field290] - [Form].[Field289] - [Form].[Field288] - [Form].[Field287] - [Form].[Field286] -- Environment
- [Form].[Field285] - [Form].[Field284] - [Form].[Field283] - [Form].[Field344] - [Form].[Field343] -- Environment
- [Form].[Field70] - [Form].[Field72] - [Form].[Field71] - [Form].[Field74] - [Form].[Field73] -- Activities (aField351)
- [Form].[Field78] - [Form].[Field77] - [Form].[Field76] - [Form].[Field75] - [Form].[Field79] -- Activities (aField351)
- [Form].[Field485] - [Form].[Field489] - [Form].[Field488] - [Form].[Field487] - [Form].[Field486] - [Form].[Field491] - [Form].[Field490] -- CDM - General
) AS [Total] INTO [dbo].[vSiteInspectionWater]
FROM
(SELECT
[af].[Name]
,[af].[aField875]
,[af].[aField874]
,[af].[TimeTag1]
,[pd].[TimeTag2]
,[f46].[number] AS [Field46] -- GARD Handheld Device Available and Working?
,[f2].[number] AS [Field2] -- Safe Systems of Work Folder
,[f4].[number] AS [Field4] -- Emergency Phone List Available On-Site
,[f5].[number] AS [Field5] -- Toilets or Toilet List Available On-Site
--------------------------------------------------------------------------
--Risk Assessments & Method Statements
--------------------------------------------------------------------------
,[f7].[number] AS [Field7] -- RAMS in Place Relevant to Work and Being followed
,[f6].[number] AS [Field6] -- Do the RAMS Cover all of the Significant Hazards
,[f12].[number] AS [Field12] -- Have the RAMS Been Briefed out to the Relevant Personell
,[f11].[number] AS [Field11] -- Are All Required Permits/Authorisations Obtained
,[f10].[number] AS [Field10] -- Are site walkways / access routes free from defects
--------------------------------------------------------------------------
-- Training/Certs
--------------------------------------------------------------------------
,[f17].[number] AS [Field17] -- All Operatives Have Required ID Cards
,[f16].[number] AS [Field16] -- Streetworks (One Person Minimum per Site)
,[f15].[number] AS [Field15] -- Operatives Face-Fit Tested Where Required?
,[f14].[number] AS [Field14] -- Operatives Hold the CSCS, SHEA Water..
--------------------------------------------------------------------------
-- P.P.E
--------------------------------------------------------------------------
,[f23].[number] AS [Field23] -- Minimum PPE Being Worn, is in Good Condition and in Date
,[f22].[number] AS [Field22] -- Task Specific PPE Being Worn, is in Good Condition and in Date
,[f21].[number] AS [Field21] -- PPE Being Stored Appropriately When Not in Use
,[f20].[number] AS [Field20] -- Wet Weather PPE Available
--------------------------------------------------------------------------
-- Emergency Preparedness
--------------------------------------------------------------------------
,CASE WHEN [f28].[number] IS NULL THEN '0' ELSE [f28].[number] END AS [Field28] -- First Aid Kit Available, in Date, Good Condition and Accessible?
,CASE WHEN [f27].[number] IS NULL THEN '0' ELSE [f27].[number] END AS [Field27] -- Eye Wash Available, in Date, Good Condition and Accessible?
,CASE WHEN [f26].[number] IS NULL THEN '0' ELSE [f26].[number] END AS [Field26] -- Fire Extinguisher Charged, in Date, Good Condition and Accessible?
,CASE WHEN [f25].[number] IS NULL THEN '0' ELSE [f25].[number] END AS [Field25] -- Gas Monitor Calibrated, in Date (where required)
,CASE WHEN [f717].[number] IS NULL THEN '0' ELSE [f717].[number] END AS [Field717] -- Outcome of the Emergency Preparedness Test
--------------------------------------------------------------------------
-- Plant and Vehicles
--------------------------------------------------------------------------
,[f34].[number] AS [Field34] -- All Vehicles Parked in a Safe Considerable Manner?
,[f33].[number] AS [Field33] -- Drivers Hold the Correct License for their Category of Vehicle and Trailer (where Towing)?
,[f32].[number] AS [Field32] -- Operators Hold an Operater License For the Plant Being Used?
,[f31].[number] AS [Field31] -- Daily Vehicle and Plant Inspections Being Completed?
,[f38].[number] AS [Field38] -- All Vehicles, Plant and Trailers Free From Defects?
,[f30].[number] AS [Field30] -- Vehicles Have Required Flashing Beacons
,[f37].[number] AS [Field37] -- All Vehicles Plant and Trailers Clean and Tidy?
,[f36].[number] AS [Field36] -- Trailer Break Away Cable in Place and Free From Defects?
,[f35].[number] AS [Field35] -- Trailer Board, Lights and Number Plate in Place, Clean and Secure?
,[f42].[number] AS [Field42] -- Are all Keys Removed From Vehicles/Plant and Equipment?
,[f41].[number] AS [Field41] -- Correct Vehicle Livery in Place for the Contract?
,[f40].[number] AS [Field40] -- Warning Stickers on Rear of Vehicle as Required (Flamable Liquid, gas or Compressed Air)
,[f39].[number] AS [Field39] -- Restraint System/Seat Belts Fitted, Used and in Good Condition?
,[f43].[number] AS [Field43] -- Vehicle Reversing Alarm Working Where Installed?
-------------------------------------------------------------------------
-- Tools and Equipment
-------------------------------------------------------------------------
,[f45].[number] AS [Field45] -- All Plant and Equipment Stored Safely Inside Barriers?
,[f50].[number] AS [Field50] -- Electrical Tools in Good Condition and Within PAT Test?
,[f49].[number] AS [Field49] -- Ladders Free From Defects and Within Inspection Date?
,[f48].[number] AS [Field48] -- Hand Tools in Good Condition and Fit for use?
,[f47].[number] AS [Field47] -- Vibrating Tools in Good Condition and Within Service Dates?
,[f53].[number] AS [Field53] -- Sthil Saw Including Blade in Good Condition with Working Dust Suppression?
,[f52].[number] AS [Field52] -- Portable Generator is in a Serviceable Condition and Being
,[f56].[number] AS [Field56] -- Stop Tap Box Cleaner Available Where Required?
,[f57].[number] AS [Field57] -- Full Set of Valve Keys Available Where Required?
,[f58].[number] AS [Field58] -- Full Set of Lifting Keys Available Where Required?
-------------------------------------------------------------------------
-- COSHH
-------------------------------------------------------------------------
,[f54].[number] AS [Field54] -- COSHH Materials Identified, Labelled Correctly
,[f62].[number] AS [Field62] -- Relevant COSHH Documents Available On-Site?
,[f61].[number] AS [Field61] -- Spill Kit Available and Personnel Familiar with its use?
,[f60].[number] AS [Field60] -- Where Atmospheric Monitoring has Been Identified
,[f59].[number] AS [Field59] -- Where Health Surveillance Has Been Identified as a Control Measure
------------------------------------------------------------------------
-- Customer
------------------------------------------------------------------------
,[f67].[number] AS [Field67] -- Customer Notification Completed Appropiately
,[f66].[number] AS [Field66] -- All Steps Being Taken to Minimise Impact on Customers
,[f65].[number] AS [Field65] -- Site Clean and Tidy
,[f64].[number] AS [Field64] -- Plastic Sheeting/Other used to Protect Custoemr Property from Spoil/Dirt
,[f68].[number] AS [Field68] -- No Spoil, Tools, Equipment Leaning up Against Customer Property
-----------------------------------------------------------------------
-- Excavations, Safe digging and Overhead lines
-----------------------------------------------------------------------
,[f266].[number] AS [Field266] -- Operatives have completed safe digging course?
,[f265].[number] AS [Field265] -- Correct & Relevant Plans
,[f271].[number] AS [Field271] -- If there is a MAHP within the work area, are the workforce aware of it?
,[f264].[number] AS [Field264] -- CAT & Genny present and in calibration?
,[f263].[number] AS [Field263] -- Spare batteries available for the CAT and Genny (minimum 6)
,[f262].[number] AS [Field262] -- Volt stick available (where required)?
,[f261].[number] AS [Field261] -- Utilities marked up with TWEG plate, entended 500m outside excavation area?
,[f260].[number] AS [Field260] -- Waterproof spray/chalk markers used?
,[f269].[number] AS [Field269] -- All digging being completed safely in line with HSG47?
,[f268].[number] AS [Field268] -- No digging within 1m of tree trunk and no roots cut over 25mm diameter?
,[f267].[number] AS [Field267] -- Spoil being stored a safe distance from excavations,
,[f274].[number] AS [Field274] -- Are there adequate measures in place to prevent people,
,[f273].[number] AS [Field273] -- Is the stability of any adjacent structures being put at risk?
,[f272].[number] AS [Field272] -- Are exposed services undamaged and adequately protected/supported?
,[f270].[number] AS [Field270] -- Have all overhead lines been identified and appropiate controls implemented?
-----------------------------------------------------------------------
-- Environment
-----------------------------------------------------------------------
,[f290].[number] AS [Field290] -- Dewatering/Pumping out away from drains,
,[f289].[number] AS [Field289] -- Dechlorination being completed where required?
,[f288].[number] AS [Field288] -- Where there are areas to be protected, are they adequately protected?
,[f287].[number] AS [Field287] -- Where required, are there adequate biosecurity arrangements in place for invasive or non-native species?
,[f286].[number] AS [Field286] -- Are adequate measures taken to prevent dust, mud, air, noise and vibration issues?
,[f285].[number] AS [Field285] -- re all waste transfer notes or equivalent being completed correctly for all waste streams?
,[f284].[number] AS [Field284] -- Has hazardous waste and non hazardous waste
,[f283].[number] AS [Field283] -- Are drip trays or plant nappies being used and maintained on site where required?
,[f344].[number] AS [Field344] -- Where necessary is a concrete washout facility provided and is it correctly used and maintained?
,[f343].[number] AS [Field343] -- Are stockpiles of excavatd material controlled to prevent silty run-off into environmentally sensitive receptors?
----------------------------------------------------------------------
-- Activities (aField351)
-- Working in the Highway
----------------------------------------------------------------------
,CASE WHEN [f70].[number] IS NULL THEN '0' ELSE [f70].[number] END AS [Field70] -- Advance warning signs in place and in good condition?
,CASE WHEN [f72].[number] IS NULL THEN '0' ELSE [f72].[number] END AS [Field72] -- Traffic lights setup correctly and working?
,CASE WHEN [f71].[number] IS NULL THEN '0' ELSE [f71].[number] END AS [Field71] -- Have appropiate lead-in and exit tapers been established as required?
,CASE WHEN [f74].[number] IS NULL THEN '0' ELSE [f74].[number] END AS [Field74] -- Barriers in place and in good condition?
,CASE WHEN [f73].[number] IS NULL THEN '0' ELSE [f73].[number] END AS [Field73] -- Cones, sufficient and in good condition?
,CASE WHEN [f78].[number] IS NULL THEN '0' ELSE [f78].[number] END AS [Field78] -- Appropiate provision for pedestian access including 1KM walkways and safety zones?
,CASE WHEN [f77].[number] IS NULL THEN '0' ELSE [f77].[number] END AS [Field77] -- Kerb ramps installed where required and in good condition?
,CASE WHEN [f76].[number] IS NULL THEN '0' ELSE [f76].[number] END AS [Field76] -- Sand bags used on all signs and every second barrier?
,CASE WHEN [f75].[number] IS NULL THEN '0' ELSE [f75].[number] END AS [Field75] -- Courtesy board in place with the correct permit number displayed?
,CASE WHEN [f79].[number] IS NULL THEN '0' ELSE [f79].[number] END AS [Field79] -- Site compliant with the requirements of the specification?
----------------------------------------------------------------------
-- CDM - General
----------------------------------------------------------------------
,CASE WHEN [f485].[number] IS NULL THEN '0' ELSE [f485].[number] END AS [Field485] -- Is there a current F10 in place and is there a copy on site?
,CASE WHEN [f489].[number] IS NULL THEN '0' ELSE [f489].[number] END AS [Field489] -- Are valid insurance certificates available?
,CASE WHEN [f488].[number] IS NULL THEN '0' ELSE [f488].[number] END AS [Field488] -- Are current Health, Safety and Environmental policies
,CASE WHEN [f487].[number] IS NULL THEN '0' ELSE [f487].[number] END AS [Field487] -- Are emergency arrangements in place and clearly displayed where applicable?
,CASE WHEN [f486].[number] IS NULL THEN '0' ELSE [f486].[number] END AS [Field486] -- Are the Site Rules briefed in the project induction and clearly visible?
,CASE WHEN [f491].[number] IS NULL THEN '0' ELSE [f491].[number] END AS [Field491] -- Have on-site staff received a project specific induction and is there evidence
,CASE WHEN [f490].[number] IS NULL THEN '0' ELSE [f490].[number] END AS [Field490] -- Are all visitors receiving a visitors induction and is there evidence on-site?
FROM [vAdvF_218] [af]
LEFT JOIN @Translate f46 ON [af].[aField46] = [f46].[string]
LEFT JOIN @Translate f2 ON [af].[aField2] = [f2].[string]
LEFT JOIN @Translate f4 ON [af].[aField4] = [f4].[string]
LEFT JOIN @Translate f5 ON [af].[aField5] = [f5].[string]
-- Risk Assessments & Method Statements
LEFT JOIN @Translate f7 ON [af].[aField7] = [f7].[string]
LEFT JOIN @Translate f6 ON [af].[aField6] = [f6].[string]
LEFT JOIN @Translate f12 ON [af].[aField12] = [f12].[string]
LEFT JOIN @Translate f11 ON [af].[aField11] = [f11].[string]
LEFT JOIN @Translate f10 ON [af].[aField10] = [f10].[string]
-- Training/Certs
LEFT JOIN @Translate f17 ON [af].[aField17] = [f17].[string]
LEFT JOIN @Translate f16 ON [af].[aField16] = [f16].[string]
LEFT JOIN @Translate f15 ON [af].[aField15] = [f15].[string]
LEFT JOIN @Translate f14 ON [af].[aField14] = [f14].[string]
-- P.P.E
LEFT JOIN @Translate f23 ON [af].[aField23] = [f23].[string]
LEFT JOIN @Translate f22 ON [af].[aField22] = [f22].[string]
LEFT JOIN @Translate f21 ON [af].[aField21] = [f21].[string]
LEFT JOIN @Translate f20 ON [af].[aField20] = [f20].[string]
-- Emergency Preparedness
LEFT JOIN @Translate f28 ON [af].[aField28] = [f28].[string]
LEFT JOIN @Translate f27 ON [af].[aField27] = [f27].[string]
LEFT JOIN @Translate f26 ON [af].[aField26] = [f26].[string]
LEFT JOIN @Translate f25 ON [af].[aField25] = [f25].[string]
LEFT JOIN @Translate f717 ON [af].[aField717] = [f717].[string]
-- Plant and Vehicles
LEFT JOIN @Translate f34 ON [af].[aField34] = [f34].[string]
LEFT JOIN @Translate f33 ON [af].[aField33] = [f33].[string]
LEFT JOIN @Translate f32 ON [af].[aField32] = [f32].[string]
LEFT JOIN @Translate f31 ON [af].[aField31] = [f31].[string]
LEFT JOIN @Translate f38 ON [af].[aField38] = [f38].[string]
LEFT JOIN @Translate f30 ON [af].[aField30] = [f30].[string]
LEFT JOIN @Translate f37 ON [af].[aField37] = [f37].[string]
LEFT JOIN @Translate f36 ON [af].[aField36] = [f36].[string]
LEFT JOIN @Translate f35 ON [af].[aField35] = [f35].[string]
LEFT JOIN @Translate f42 ON [af].[aField42] = [f42].[string]
LEFT JOIN @Translate f41 ON [af].[aField41] = [f41].[string]
LEFT JOIN @Translate f40 ON [af].[aField40] = [f40].[string]
LEFT JOIN @Translate f39 ON [af].[aField39] = [f39].[string]
LEFT JOIN @Translate f43 ON [af].[aField43] = [f43].[string]
-- Tools and Equipment
LEFT JOIN @Translate f45 ON [af].[aField45] = [f45].[string]
LEFT JOIN @Translate f50 ON [af].[aField50] = [f50].[string]
LEFT JOIN @Translate f49 ON [af].[aField49] = [f49].[string]
LEFT JOIN @Translate f48 ON [af].[aField48] = [f48].[string]
LEFT JOIN @Translate f47 ON [af].[aField47] = [f47].[string]
LEFT JOIN @Translate f53 ON [af].[aField53] = [f53].[string]
LEFT JOIN @Translate f52 ON [af].[aField52] = [f52].[string]
LEFT JOIN @Translate f56 ON [af].[aField56] = [f56].[string]
LEFT JOIN @Translate f57 ON [af].[aField57] = [f57].[string]
LEFT JOIN @Translate f58 ON [af].[aField58] = [f58].[string]
-- COSHH
LEFT JOIN @Translate f54 ON [af].[aField54] = [f54].[string]
LEFT JOIN @Translate f62 ON [af].[aField62] = [f62].[string]
LEFT JOIN @Translate f61 ON [af].[aField61] = [f61].[string]
LEFT JOIN @Translate f60 ON [af].[aField60] = [f60].[string]
LEFT JOIN @Translate f59 ON [af].[aField59] = [f59].[string]
LEFT JOIN @Translate f67 ON [af].[aField67] = [f67].[string]
LEFT JOIN @Translate f66 ON [af].[aField66] = [f66].[string]
LEFT JOIN @Translate f65 ON [af].[aField65] = [f65].[string]
LEFT JOIN @Translate f64 ON [af].[aField64] = [f64].[string]
LEFT JOIN @Translate f68 ON [af].[aField68] = [f68].[string]
LEFT JOIN @Translate f266 ON [af].[aField266] = [f266].[string]
LEFT JOIN @Translate f265 ON [af].[aField265] = [f265].[string]
LEFT JOIN @Translate f271 ON [af].[aField271] = [f271].[string]
LEFT JOIN @Translate f264 ON [af].[aField264] = [f264].[string]
LEFT JOIN @Translate f263 ON [af].[aField263] = [f263].[string]
LEFT JOIN @Translate f262 ON [af].[aField262] = [f262].[string]
LEFT JOIN @Translate f261 ON [af].[aField261] = [f261].[string]
LEFT JOIN @Translate f260 ON [af].[aField260] = [f260].[string]
LEFT JOIN @Translate f269 ON [af].[aField269] = [f269].[string]
LEFT JOIN @Translate f268 ON [af].[aField268] = [f268].[string]
LEFT JOIN @Translate f267 ON [af].[aField267] = [f267].[string]
LEFT JOIN @Translate f274 ON [af].[aField274] = [f274].[string]
LEFT JOIN @Translate f273 ON [af].[aField273] = [f273].[string]
LEFT JOIN @Translate f272 ON [af].[aField272] = [f272].[string]
LEFT JOIN @Translate f270 ON [af].[aField270] = [f270].[string]
-- Environment
LEFT JOIN @Translate f290 ON [af].[aField290] = [f290].[string]
LEFT JOIN @Translate f289 ON [af].[aField289] = [f289].[string]
LEFT JOIN @Translate f288 ON [af].[aField288] = [f288].[string]
LEFT JOIN @Translate f287 ON [af].[aField287] = [f287].[string]
LEFT JOIN @Translate f286 ON [af].[aField286] = [f286].[string]
LEFT JOIN @Translate f285 ON [af].[aField285] = [f285].[string]
LEFT JOIN @Translate f284 ON [af].[aField284] = [f284].[string]
LEFT JOIN @Translate f283 ON [af].[aField283] = [f283].[string]
LEFT JOIN @Translate f344 ON [af].[aField344] = [f344].[string]
LEFT JOIN @Translate f343 ON [af].[aField343] = [f343].[string]
-- Activities
LEFT JOIN @Translate f70 ON [af].[aField70] = [f70].[string]
LEFT JOIN @Translate f72 ON [af].[aField72] = [f72].[string]
LEFT JOIN @Translate f71 ON [af].[aField71] = [f71].[string]
LEFT JOIN @Translate f74 ON [af].[aField74] = [f74].[string]
LEFT JOIN @Translate f73 ON [af].[aField73] = [f73].[string]
LEFT JOIN @Translate f78 ON [af].[aField78] = [f78].[string]
LEFT JOIN @Translate f77 ON [af].[aField77] = [f77].[string]
LEFT JOIN @Translate f76 ON [af].[aField76] = [f76].[string]
LEFT JOIN @Translate f75 ON [af].[aField75] = [f75].[string]
LEFT JOIN @Translate f79 ON [af].[aField79] = [f79].[string]
-- CDM - General
LEFT JOIN @Translate f485 ON [af].[aField485] = [f485].[string]
LEFT JOIN @Translate f489 ON [af].[aField489] = [f489].[string]
LEFT JOIN @Translate f488 ON [af].[aField488] = [f488].[string]
LEFT JOIN @Translate f487 ON [af].[aField487] = [f487].[string]
LEFT JOIN @Translate f486 ON [af].[aField486] = [f486].[string]
LEFT JOIN @Translate f491 ON [af].[aField491] = [f491].[string]
LEFT JOIN @Translate f490 ON [af].[aField490] = [f490].[string]
INNER JOIN [PhoneData] [pd] ON [af].[RecId] = [pd].[recid]) AS [Form]
答案 0 :(得分:0)
通过重新设计脚本并创建一个CURSOR来解决,该CURSOR通过SP运行并将数据拉入数据立方体。