我需要将 text( SQL
) 添加/附加到现有script
.
我有一个为我STORED PROCEDURE
生成INSERT statements
的。它们已退出分配,因此目前我将它们复制并粘贴到所需的scripts
.
这基本上是 SQL 的样子:
SELECT '' + CHAR(13) + CHAR(10) + 'EXECUTE [procSystemAppEntity_InsertOrUpdate] ' + CHAR(13) + CHAR(10) + ' @SystemUID = @SystemUID' + CHAR(13) + CHAR(10)
+ ',@SystemAppCode = @SystemAppCode' + CHAR(13) + CHAR(10)
+ ',@SystemAppEntityTypeCode = N''' + saet.[SystemAppEntityTypeCode] + '''' + CHAR(13) + CHAR(10)
+ ',@SystemAppEntityUID = '''+ CAST((SELECT NEWID()) AS nvarchar(max)) + '''' + CHAR(13) + CHAR(10)
+ ',@SystemAppEntityCode = ''' + tab.name + '''' + CHAR(13) + CHAR(10)
+ ',@SystemAppEntityName = N''' + tab.name + '''' + CHAR(13) + CHAR(10)
+ ',@TableName = N''' + tab.name + '''' + CHAR(13) + CHAR(10)
+ ',@TableKeyColumnName = N''' + tab.name + 'ID''' + CHAR(13) + CHAR(10)
+ ',@TableKeyCodeColumnName = N''' + tab.name + 'Code''' + CHAR(13) + CHAR(10)
+ ',@ManagedAssemblyName = N''' + CASE WHEN @SystemAppEntityManagedAssemblyName IS NULL THEN '' ELSE @SystemAppEntityManagedAssemblyName END + '''' + CHAR(13) + CHAR(10)
+ ', @ManagedNamespace = N''' + CASE WHEN @SystemAppEntityManagedNamespace IS NULL THEN '' ELSE @SystemAppEntityManagedNamespace END + '''' + CHAR(13) + CHAR(10)
+ ', @ManagedClassName = ''' + tab.name + '''' + CHAR(13) + CHAR(10)
+ ', @IsMultiple = ' + CAST(@IsMultiple AS varchar(1)) + CHAR(13) + CHAR(10)
+ ', @IsCodeGenerated = 1' + CHAR(13) + CHAR(10)
+ ', @IsActive = 1' + CHAR(13) + CHAR(10)
+ ', @SystemAppUserID = @CreationSystemAppUserID ' + CHAR(13) + CHAR(10) + '; '
FROM sys.tables tab INNER JOIN
[SystemAppEntityType] saet ON saet.[IsMultipleEntity] = CASE WHEN RIGHT(tab.name, 1) = 's' THEN 1 ELSE 0 END AND saet.[IsNavigationEntity] = 0 AND saet.IsSystemEntity = CASE WHEN LEFT(tab.name, 3) = 'Sys' THEN 1 ELSE 0 END
WHERE (tab.name NOT IN (SELECT e.[TableName] FROM [SystemAppEntity] e))
AND (tab.name = @Code)
输出为:
EXECUTE [procSystemAppEntity_InsertOrUpdate]
@SystemUID = @SystemUID
,@SystemAppCode = @SystemAppCode
,@SystemAppEntityTypeCode = N'App-S'
,@SystemAppEntityUID = '11E347C7-7E69-4555-A6F0-2AFE142FC25F'
,@SystemAppEntityCode = 'Revision'
,@SystemAppEntityName = N'Revision'
,@TableName = N'Revision'
,@TableKeyColumnName = N'RevisionID'
,@TableKeyCodeColumnName = N'RevisionCode'
,@ManagedAssemblyName = N'SomeManagedAssemblyName '
, @ManagedNamespace = N'SomeManagedNamespace '
, @ManagedClassName = 'Revision'
, @IsMultiple = 0
, @IsCodeGenerated = 1
, @IsIntegratedToStaging = 1
, @IsActive = 1
, @SystemAppUserID = @CreationSystemAppUserID
;
话虽这么说,有没有一种方法可以让我Output statements
直接将其写入/附加到所需的脚本?
我只是希望它添加到脚本的底部。这可能吗?如果可以,我将如何实现?