DECLARE @sqlquery NVARCHAR(4000)
DECLARE RemoveCr CURSOR FOR
SELECT DISTINCT --m.Name, e.Name,
e.EntityTable, a.DisplayName,a.TableColumn, e.*,
'UPDATE mdm.' + e.EntityTable + ' SET ' + a.TableColumn + ' = SUBSTRING(' + a.TableColumn + ', 0, CHARINDEX ( CHAR(13),
' + a.TableColumn
+ ' ) ) WHERE ' + a.TableColumn + ' LIKE ''%'' + CHAR(13) +
CHAR(10)+ ''%'''
--'SELECT ' +
a.TableColumn + ' FROM mdm.' + e.EntityTable + ' WHERE ' + a.TableColumn + '
LIKE ''%'' + CHAR(13) + CHAR(10)+ ''%'''
FROM mdm.tblEntity e
INNER JOIN mdm.tblModel m ON e.Model_ID = m.ID
INNER JOIN mdm.tblModelVersion
mv ON m.ID = mv.Model_ID
INNER JOIN mdm.tblAttribute
a ON a.Entity_ID
= e.ID
INNER JOIN mdm.tblList lAtt
ON a.AttributeType_ID
= lAtt.OptionID
AND lAtt.ListCode
= 'lstAttributeType'
INNER JOIN mdm.tblList lDat
ON a.DataType_ID
= lAtt.OptionID
AND lDat.ListCode
= 'lstDataType'
WHERE m.Name <> 'Metadata'
AND mv.Name = 'VERSION_1'
AND lAtt.ListOption <> 'System'
AND lDat.ListOption = 'Text'
AND IsBase = 0
OPEN RemoveCr
FETCH NEXT FROM RemoveCr INTO @sqlquery
WHILE (@@FETCH_STATUS = 0)
BEGIN
EXEC(@sqlquery)
FETCH NEXT FROM RemoveCr INTO @sqlquery
END
CLOSE RemoveCr
DEALLOCATE RemoveCr
No comments:
Post a Comment