IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0V1PROCESSSTEPS')
BEGIN
DROP VIEW LD0V1PROCESSSTEPS 
END
;
CREATE VIEW LD0V1PROCESSSTEPS AS
SELECT S.*,  
CASE WHEN S.ID IN (
     SELECT DISTINCT(STEPID) FROM LD0P0PROCESSSTEPCOMPONENTMAPPING SCM  WHERE EXISTS  
    (SELECT ID FROM LD0P0SAVEDCOMPONENTS SC WHERE SC.STEPCOMPONENTMAPPINGID = SCM.ID)
     ) 
 THEN 1 
 ELSE 0 
 END AS ISSTEPUSED
FROM LD0P0PROCESSSTEPS S
;