SQL 服务器 2000 截断 SQL 使用动态生成的字符串 SQL

SQL SERVER 2000 TRUNCATES SQL STRING GENERATED USING DYNAMIC SQL

我正在尝试使用以下代码生成超过 90 table 秒的更新语句:

   Declare @cmd   VARCHAR(8000)

       Select @cmd =  COALESCE(@cmd,'') +
      '
         UPDATE ' + TABLE_NAME + ' SET ' + Column_Name + '  = ''000000000''' + '''
         WHERE ' + Column_Name + '  = ''000000001''' + '''
      '


        From INFORMATION_SCHEMA.COLUMNS
                  Where TABLE_NAME not in (SELECT TABLE_NAME
                        From INFORMATION_SCHEMA.VIEWS)
                   and 
                        (Column_Name like 'SSN%'       
                        OR Column_Name LIKE 'ssn%'          
                        OR Column_Name LIKE 'ssn%'          
                        OR Column_Name LIKE '%_ssn%'            
                        OR Column_Name LIKE '_ocsecno'          
                        OR Column_Name LIKE 'Ssn%');

          Select @cmd

代码有效,但 SQL 服务器 2000 只能生成 91 table 秒中的 45 table 秒的更新语句。它在第 45 个 table 处截断 SQL 字符串。有谁知道如何解决这个问题?

如果您只是想生成更新语句,您可以将更新插入临时 table。

SELECT
    '
        UPDATE ' + TABLE_NAME + ' SET ' + Column_Name + '  = ''000000000''' + '''
        WHERE ' + Column_Name + '  = ''000000001''' + '''
    ' AS [query]
INTO
    #tempCmd
FROM
    INFORMATION_SCHEMA.COLUMNS
WHERE
    TABLE_NAME NOT IN (SELECT
                    TABLE_NAME
                    FROM
                    INFORMATION_SCHEMA.VIEWS)
    AND (Column_Name LIKE 'SSN%'
        OR Column_Name LIKE 'ssn%'
        OR Column_Name LIKE 'ssn%'
        OR Column_Name LIKE '%_ssn%'
        OR Column_Name LIKE '_ocsecno'
        OR Column_Name LIKE 'Ssn%');

SELECT [query] FROM #tempCmd