У меня есть набор данных, который генерируется SP, SP вызывает представление внутри него. Мне нужен дополнительный столбец в наборе результатов под названием «Scorable», который должен быть установлен в 1 только для узла, который является последним, но один.
ALTER PROCEDURE [dbo].[SP_GetNodes] ---1252,211
(
@ParentId nvarchar(max),
@instanceId int
)
AS
declare @highest as int
set @highest = (select max(level) as level from [dbo].[vwAssesment] where instanceid=@instanceId )
print @highest
set @highest = @highest - 1
print @highest
(select * , CASE
WHEN level = @highest THEN 0 when level = 4 then 0 else 1 end as Scorable from [dbo].[vwAssesment] where path like @ParentId+'/%' and instanceid=@instanceId
union all
select * , 0 as Scorable from [dbo].[vwAssesment] where structureid = @ParentId and instanceid=@instanceId ) order by structureid
Просмотр
CREATE VIEW [dbo].[vwAssesment]
AS
WITH tree AS
(
SELECT c1.structureid,c1.assessmentid, c1.sequence,c1.Required,c1.Objective, 1 [depth],cast(isnull([sequence],'') as varchar(max)) Tree_full_index, c1.parentid, c1.Text, [level] = 1, path = cast( c1.structureid as varchar(100))
FROM [ast].[Structure] c1
WHERE c1.parentid IS NULL
UNION ALL
SELECT c2.structureid, c2.assessmentid, c2.sequence,c2.Required,c2.Objective, tree.depth+1 [depth],cast(tree.Tree_full_index + '.0'+cast(isnull(c2.sequence,'') as varchar(3)) as varchar(max)) Tree_full_index, c2.parentid, c2.Text, [level] = tree.[level] + 1,
Path = Cast(tree.path+'/'+right('000000000' + cast(c2.structureid as varchar(10)),10) as varchar(100))
FROM [ast].[Structure] c2 INNER JOIN tree ON tree.structureid = c2.parentid
)
SELECT tree.level,tree.sequence,
tree.path, parentid, tree.assessmentid, tree.Required,tree.Objective,Tree_full_index+' '+ tree.Text AS description ,C.* ,
wasScored = (case when C.choiceid is null then 0 else 1 end ),
wasDerived = (case when C.choiceid is null and C.Score is not null then 1 else 0 end )
FROM tree inner join [ast].[Value] as C on tree.structureid = C.structureid
Если вы видите индекс на уровне 7, следует установить в столбце «Scurable» записи «7.07.01 Выполнить первоначальную очистку и осмотр (Уровень 1)», «7.07.02 Устранить причины загрязнения и недоступные участки (Уровень2) «» 7.07.03 Разработать стандарты очистки, смазки и проверки (уровень 3) », потому что это последние, кроме одного узла. и столбец должен быть установлен от 0 до "7,07 TPM", потому что это не последний, а один индекс.
level sequence path parentid assessmentid Required Objective description ValueId InstanceId StructureId ChoiceId Score wasScored wasDerived Scorable
1 7 2496 NULL 157 1 ensure driving foundation for Continuous Improvement culture to be successful and achieve meaningful results 7 Continuous Improvement 1754 217 2496 NULL NULL 0 0 0
2 1 2496/0000002514 2496 157 1 Gemba 7.01 Gemba 1772 217 2514 NULL NULL 0 0 1
2 2 2496/0000002515 2496 157 1 Real-Time status 7.02 Real-Time status 1773 217 2515 NULL NULL 0 0 1
2 3 2496/0000002516 2496 157 1 Team Members 7.03 Team Members 1774 217 2516 NULL NULL 0 0 1
3 1 2496/0000002514/0000002765 2514 157 1 Routine and scheduled 7.01.01 Routine and scheduled 2023 217 2765 NULL NULL 0 0 0
3 2 2496/0000002514/0000002766 2514 157 1 Incorporated into appropriate different levels of organization (Facility Manager, Staff, site Director) 7.01.02 Incorporated into appropriate different levels of organization (Facility Manager, Staff, site Director) 2024 217 2766 NULL NULL 0 0 0
3 1 2496/0000002515/0000002767 2515 157 1 % of total process that display and utilize real-time status / information to make decisions and generate alerts for abnormalities that occur 7.02.01 % of total process that display and utilize real-time status / information to make decisions and generate alerts for abnormalities that occur 2025 217 2767 NULL NULL 0 0 0
3 1 2496/0000002516/0000002768 2516 157 1 Team members are trained with the appropriate skill in order to be able to respond and drive resolution for abnormalities that occur 7.03.01 Team members are trained with the appropriate skill in order to be able to respond and drive resolution for abnormalities that occur 2026 217 2768 NULL NULL 0 0 0
3 2 2496/0000002516/0000002769 2516 157 1 Documented Counter Measures are utilized 7.03.02 Documented Counter Measures are utilized 2027 217 2769 NULL NULL 0 0 0
3 3 2496/0000002516/0000002770 2516 157 1 RCA or appropriate training conducted with formal projects contained in Lean Project Tracker 7.03.03 RCA or appropriate training conducted with formal projects contained in Lean Project Tracker 2028 217 2770 NULL NULL 0 0 0
2 4 2496/0000002771 2496 157 1 Key Processes Setup Reduction 7.04 Key Processes Setup Reduction 2029 217 2771 NULL NULL 0 0 1
3 1 2496/0000002771/0000002772 2771 157 1 Key processes are identified with baseline establish for setup time 7.04.01 Key processes are identified with baseline establish for setup time 2030 217 2772 NULL NULL 0 0 0
3 2 2496/0000002771/0000002773 2771 157 1 Kaizens are either completed, underway or schedule to reduce setup times with list of projects in Lean Project Tracker 7.04.02 Kaizens are either completed, underway or schedule to reduce setup times with list of projects in Lean Project Tracker 2031 217 2773 NULL NULL 0 0 0
3 3 2496/0000002771/0000002774 2771 157 1 Key processes are monitored and trends established of setup times 7.04.03 Key processes are monitored and trends established of setup times 2032 217 2774 NULL NULL 0 0 0
3 4 2496/0000002771/0000002775 2771 157 1 Graphical depiction of setup trends are used to manage throughput on Key Processes 7.04.04 Graphical depiction of setup trends are used to manage throughput on Key Processes 2033 217 2775 NULL NULL 0 0 0
2 5 2496/0000002776 2496 157 1 Business Performance GAPs 7.05 Business Performance GAPs 2034 217 2776 NULL NULL 0 0 1
3 1 2496/0000002776/0000002777 2776 157 1 Identify performance GAPs, understand where the gap is, why the gap exists and benefits of closing the gap 7.05.01 Identify performance GAPs, understand where the gap is, why the gap exists and benefits of closing the gap 2035 217 2777 NULL NULL 0 0 0
3 2 2496/0000002776/0000002778 2776 157 1 Address these GAPs and prioritize, drive action to resolve by applying Operational Excellence concepts and tools to accomplish desired objectives 7.05.02 Address these GAPs and prioritize, drive action to resolve by applying Operational Excellence concepts and tools to accomplish desired objectives 2036 217 2778 NULL NULL 0 0 0
3 3 2496/0000002776/0000002779 2776 157 1 Close performance GAPs by allocating resources (time & people) to taking action 7.05.03 Close performance GAPs by allocating resources (time & people) to taking action 2037 217 2779 NULL NULL 0 0 0
2 6 2496/0000002780 2496 157 1 SPP (Single Page Plan A3) 7.06 SPP (Single Page Plan A3) 2038 217 2780 NULL NULL 0 0 1
3 1 2496/0000002780/0000002781 2780 157 1 SPP used to document Continuous Improvement activities 7.06.01 SPP used to document Continuous Improvement activities 2039 217 2781 NULL NULL 0 0 0
3 2 2496/0000002780/0000002782 2780 157 1 SPP part of projected documented in Lean Project Tracker 7.06.02 SPP part of projected documented in Lean Project Tracker 2040 217 2782 NULL NULL 0 0 0
2 7 2496/0000002783 2496 157 1 TPM Methodology - incorporate TPM and achieve Level 7 throughout facility. 7.07 TPM 2041 217 2783 NULL NULL 0 0 1
3 1 2496/0000002783/0000002784 2783 157 1 Perform initial Cleaning & Inspection (Level 1) 7.07.01 Perform initial Cleaning & Inspection (Level 1) 2042 217 2784 NULL NULL 0 0 0
4 1 2496/0000002783/0000002784/0000002785 2784 157 1 Learn how to identify equipment problems 7.07.01.01 Learn how to identify equipment problems 2043 217 2785 NULL NULL 0 0 0
4 2 2496/0000002783/0000002784/0000002786 2784 157 1 Operators responsible for upkeep of their equipment 7.07.01.02 Operators responsible for upkeep of their equipment 2044 217 2786 NULL NULL 0 0 0
4 3 2496/0000002783/0000002784/0000002787 2784 157 1 Becomes part of daily routine 7.07.01.03 Becomes part of daily routine 2045 217 2787 NULL NULL 0 0 0
4 4 2496/0000002783/0000002784/0000002788 2784 157 1 Implement first three of the 5S program, Sort, Set in Order and Shine 7.07.01.04 Implement first three of the 5S program, Sort, Set in Order and Shine 2046 217 2788 NULL NULL 0 0 0
3 2 2496/0000002783/0000002789 2783 157 1 Eliminate causes of Contamination & Inaccessible areas (Level 2) 7.07.02 Eliminate causes of Contamination & Inaccessible areas (Level 2) 2047 217 2789 NULL NULL 0 0 0
4 1 2496/0000002783/0000002789/0000002790 2789 157 1 Stop contaminants at their source 7.07.02.01 Stop contaminants at their source 2048 217 2790 NULL NULL 0 0 0
4 2 2496/0000002783/0000002789/0000002791 2789 157 1 Focus on obstacles preventing effective cleaning & inspection 7.07.02.02 Focus on obstacles preventing effective cleaning & inspection 2049 217 2791 NULL NULL 0 0 0
4 3 2496/0000002783/0000002789/0000002792 2789 157 1 Drive improvement activities 7.07.02.03 Drive improvement activities 2050 217 2792 NULL NULL 0 0 0
4 4 2496/0000002783/0000002789/0000002793 2789 157 1 Get all team members involved 7.07.02.04 Get all team members involved 2051 217 2793 NULL NULL 0 0 0
3 3 2496/0000002783/0000002794 2783 157 1 Develop cleaning, lubricating and inspection standards (Level 3) 7.07.03 Develop cleaning, lubricating and inspection standards (Level 3) 2052 217 2794 NULL NULL 0 0 0
4 1 2496/0000002783/0000002794/0000002795 2794 157 1 Sustain Level 1 and 2 7.07.03.01 Sustain Level 1 and 2 2053 217 2795 NULL NULL 0 0 0
4 2 2496/0000002783/0000002794/0000002796 2794 157 1 Develop standards for cleaning, lubricating and inspection 7.07.03.02 Develop standards for cleaning, lubricating and inspection 2054 217 2796 NULL NULL 0 0 0
4 3 2496/0000002783/0000002794/0000002797 2794 157 1 Team members should be actively involved daily 7.07.03.03 Team members should be actively involved daily 2055 217 2797 NULL NULL 0 0 0
3 4 2496/0000002783/0000002798 2783 157 0 Provide basic training in Machine's function and controls (Level 4) 7.07.04 Provide basic training in Machine's function and controls (Level 4) 2056 217 2798 NULL NULL 0 0 0
4 1 2496/0000002783/0000002798/0000002799 2798 157 0 Enables effective inspection 7.07.04.01 Enables effective inspection 2057 217 2799 NULL NULL 0 0 0
4 2 2496/0000002783/0000002798/0000002800 2798 157 0 Increases team member's knowledge and skills in inspecting equipment and performing diagnostics 7.07.04.02 Increases team member's knowledge and skills in inspecting equipment and performing diagnostics 2058 217 2800 NULL NULL 0 0 0
4 3 2496/0000002783/0000002798/0000002801 2798 157 0 Increase scope of team member's work 7.07.04.03 Increase scope of team member's work 2059 217 2801 NULL NULL 0 0 0
4 4 2496/0000002783/0000002798/0000002802 2798 157 0 Apply visual controls 7.07.04.04 Apply visual controls 2060 217 2802 NULL NULL 0 0 0
3 5 2496/0000002783/0000002803 2783 157 0 Enhance and implement Autonomous inspection standards & schedules (Level 5) 7.07.05 Enhance and implement Autonomous inspection standards & schedules (Level 5) 2061 217 2803 NULL NULL 0 0 0
4 1 2496/0000002783/0000002803/0000002804 2803 157 0 Update and finalize standards 7.07.05.01 Update and finalize standards 2062 217 2804 NULL NULL 0 0 0
4 2 2496/0000002783/0000002803/0000002805 2803 157 0 Update and finalize schedules for Autonomous maintenance activies, preventive maintenance and audits 7.07.05.02 Update and finalize schedules for Autonomous maintenance activies, preventive maintenance and audits 2063 217 2805 NULL NULL 0 0 0
4 3 2496/0000002783/0000002803/0000002806 2803 157 0 Systematic and routine improvement activities 7.07.05.03 Systematic and routine improvement activities 2064 217 2806 NULL NULL 0 0 0
3 6 2496/0000002783/0000002807 2783 157 0 Implement workplace organization and housekeeping, employing 5S, WPO and Visual Controls (Level 6) 7.07.06 Implement workplace organization and housekeeping, employing 5S, WPO and Visual Controls (Level 6) 2065 217 2807 NULL NULL 0 0 0
4 1 2496/0000002783/0000002807/0000002808 2807 157 0 Ensure transparency within the workplace 7.07.06.01 Ensure transparency within the workplace 2066 217 2808 NULL NULL 0 0 0
4 2 2496/0000002783/0000002807/0000002809 2807 157 0 All roles and areas of responsibilities are clearly defined 7.07.06.02 All roles and areas of responsibilities are clearly defined 2067 217 2809 NULL NULL 0 0 0
4 3 2496/0000002783/0000002807/0000002810 2807 157 0 Abnormailities are easily and quickly detected 7.07.06.03 Abnormailities are easily and quickly detected 2068 217 2810 NULL NULL 0 0 0
4 4 2496/0000002783/0000002807/0000002811 2807 157 0 Escalation process known and followed 7.07.06.04 Escalation process known and followed 2069 217 2811 NULL NULL 0 0 0
4 5 2496/0000002783/0000002807/0000002812 2807 157 0 Where possible, team member has skill set at point of need to drive resolution 7.07.06.05 Where possible, team member has skill set at point of need to drive resolution 2070 217 2812 NULL NULL 0 0 0
3 7 2496/0000002783/0000002813 2783 157 0 Follow up on all the above steps and apply advanced improvement techniques (Level 7) 7.07.07 Follow up on all the above steps and apply advanced improvement techniques (Level 7) 2071 217 2813 NULL NULL 0 0 0
4 1 2496/0000002783/0000002813/0000002814 2813 157 0 Strengthen and consolidate TPM teams 7.07.07.01 Strengthen and consolidate TPM teams 2072 217 2814 NULL NULL 0 0 0
4 2 2496/0000002783/0000002813/0000002815 2813 157 0 Focus on continuous improvement 7.07.07.02 Focus on continuous improvement 2073 217 2815 NULL NULL 0 0 0
4 3 2496/0000002783/0000002813/0000002816 2813 157 0 Focus on refinement of standards 7.07.07.03 Focus on refinement of standards 2074 217 2816 NULL NULL 0 0 0
4 4 2496/0000002783/0000002813/0000002817 2813 157 0 Benefits should include Improved Quality, improved uptime and reduced expense 7.07.07.04 Benefits should include Improved Quality, improved uptime and reduced expense 2075 217 2817 NULL NULL 0 0 0
4 5 2496/0000002783/0000002813/0000002818 2813 157 0 Team members continue to build diagnostic and maintenance skill set 7.07.07.05 Team members continue to build diagnostic and maintenance skill set 2076 217 2818 NULL NULL 0 0 0
2 8 2496/0000002819 2496 157 1 DLM 7.08 DLM 2077 217 2819 NULL NULL 0 0 1
3 1 2496/0000002819/0000002820 2819 157 1 Leader Standard Work 7.08.01 Leader Standard Work 2078 217 2820 NULL NULL 0 0 0
4 1 2496/0000002819/0000002820/0000002821 2820 157 1 Daily routine develop for all levels 7.08.01.01 Daily routine develop for all levels 2079 217 2821 NULL NULL 0 0 0
4 2 2496/0000002819/0000002820/0000002822 2820 157 1 Help develop Lean Learning Organization through Gemba 7.08.01.02 Help develop Lean Learning Organization through Gemba 2080 217 2822 NULL NULL 0 0 0
3 2 2496/0000002819/0000002823 2819 157 1 Visual Controls and Visual Control Boards 7.08.02 Visual Controls and Visual Control Boards 2081 217 2823 NULL NULL 0 0 0
4 1 2496/0000002819/0000002823/0000002824 2823 157 1 Two-way communication platform 7.08.02.01 Two-way communication platform 2082 217 2824 NULL NULL 0 0 0
4 2 2496/0000002819/0000002823/0000002825 2823 157 1 Enables all team members to compare current status to targets 7.08.02.02 Enables all team members to compare current status to targets 2083 217 2825 NULL NULL 0 0 0
4 3 2496/0000002819/0000002823/0000002826 2823 157 1 Visually identify abnormalities verses normal conditions 7.08.02.03 Visually identify abnormalities verses normal conditions 2084 217 2826 NULL NULL 0 0 0
4 4 2496/0000002819/0000002823/0000002827 2823 157 1 Develop Counter Measures for most common abnormalities 7.08.02.04 Develop Counter Measures for most common abnormalities 2085 217 2827 NULL NULL 0 0 0
4 5 2496/0000002819/0000002823/0000002828 2823 157 1 Make it obvious when conditions are nonstandard and abnormal 7.08.02.05 Make it obvious when conditions are nonstandard and abnormal 2086 217 2828 NULL NULL 0 0 0
3 3 2496/0000002819/0000002829 2819 157 1 Daily Accountability 7.08.03 Daily Accountability 2087 217 2829 NULL NULL 0 0 0
4 1 2496/0000002819/0000002829/0000002830 2829 157 1 Daily accountability for performance 7.08.03.01 Daily accountability for performance 2088 217 2830 NULL NULL 0 0 0
4 2 2496/0000002819/0000002829/0000002831 2829 157 1 Ensure daily improvements to provide stable performance 7.08.03.02 Ensure daily improvements to provide stable performance 2089 217 2831 NULL NULL 0 0 0
3 4 2496/0000002819/0000002832 2819 157 1 Structured Problem Solving 7.08.04 Structured Problem Solving 2090 217 2832 NULL NULL 0 0 0
4 1 2496/0000002819/0000002832/0000002833 2832 157 1 Capture issues at point-of-need 7.08.04.01 Capture issues at point-of-need 2091 217 2833 NULL NULL 0 0 0
4 2 2496/0000002819/0000002832/0000002834 2832 157 1 Diverse cross-functional team develop and deploy resolution based on PDCA / Scientific Thinking / Kata approach 7.08.04.02 Diverse cross-functional team develop and deploy resolution based on PDCA / Scientific Thinking / Kata approach 2092 217 2834 NULL NULL 0 0 0
3 5 2496/0000002819/0000002835 2819 157 1 Daily Lead Board Meeting 7.08.05 Daily Lead Board Meeting 2093 217 2835 NULL NULL 0 0 0
4 1 2496/0000002819/0000002835/0000002836 2835 157 1 Support platform to help manage daily requirements and resolve abnormalities 7.08.05.01 Support platform to help manage daily requirements and resolve abnormalities 2094 217 2836 NULL NULL 0 0 0
4 2 2496/0000002819/0000002835/0000002837 2835 157 1 Lead Board's are utilized Daily 7.08.05.02 Lead Board's are utilized Daily 2095 217 2837 NULL NULL 0 0 0
4 3 2496/0000002819/0000002835/0000002838 2835 157 1 Lead Board's follow Standard Forma 7.08.05.03 Lead Board's follow Standard Forma 2096 217 2838 NULL NULL 0 0 0
4 4 2496/0000002819/0000002835/0000002839 2835 157 1 Lead Board's priority are 1. Safety, 2. Quality, 3. Delivery, 4. Cost 7.08.05.04 Lead Board's priority are 1. Safety, 2. Quality, 3. Delivery, 4. Cost 2097 217 2839 NULL NULL 0 0 0
3 6 2496/0000002819/0000002840 2819 157 1 Process Focus 7.08.06 Process Focus 2098 217 2840 NULL NULL 0 0 0
4 1 2496/0000002819/0000002840/0000002841 2840 157 1 Focused process improvements 7.08.06.01 Focused process improvements 2099 217 2841 NULL NULL 0 0 0
4 2 2496/0000002819/0000002840/0000002842 2840 157 1 Validate through Layered Process Audits to ensure Counter-Measures and Standard Work are in place 7.08.06.02 Validate through Layered Process Audits to ensure Counter-Measures and Standard Work are in place 2100 217 2842 NULL NULL 0 0 0
2 9 2496/0000002843 2496 157 1 Value Stream Maps 7.09 Value Stream Maps 2101 217 2843 NULL NULL 0 0 1
3 1 2496/0000002843/0000002844 2843 157 1 VSM for Current State & Future State have identified improvement opportunities for: 7.09.01 VSM for Current State & Future State have identified improvement opportunities for: 2102 217 2844 NULL NULL 0 0 0
3 2 2496/0000002843/0000002845 2843 157 1 Flow constraints 7.09.02 Flow constraints 2103 217 2845 NULL NULL 0 0 0
3 3 2496/0000002843/0000002846 2843 157 1 Overproduction opportunities 7.09.03 Overproduction opportunities 2104 217 2846 NULL NULL 0 0 0
3 4 2496/0000002843/0000002847 2843 157 1 Causes for shipment delays 7.09.04 Causes for shipment delays 2105 217 2847 NULL NULL 0 0 0
3 5 2496/0000002843/0000002848 2843 157 1 Current Quality issues 7.09.05 Current Quality issues 2106 217 2848 NULL NULL 0 0 0
3 6 2496/0000002843/0000002849 2843 157 1 Provide linkage to K100 activities and Green Belt projects 7.09.06 Provide linkage to K100 activities and Green Belt projects 2107 217 2849 NULL NULL 0 0 0
2 10 2496/0000002850 2496 157 1 K100 Associate 7.010 K100 Associate 2108 217 2850 NULL NULL 0 0 1
3 1 2496/0000002850/0000002851 2850 157 1 Site beginning to implement K100 Associate certification 7.010.01 Site beginning to implement K100 Associate certification 2109 217 2851 NULL NULL 0 0 0
3 2 2496/0000002850/0000002852 2850 157 1 Certification goal of 100% participation for Bronze Level 7.010.02 Certification goal of 100% participation for Bronze Level 2110 217 2852 NULL NULL 0 0 0