SQL Server存储过程 - 返回包含字母数字结果的3个字符行号的逻辑

问题描述 投票:-3回答:1
OPEN abcTables
    FETCH NEXT FROM abcTables INTO @TableName
    WHILE @@FETCH_STATUS = 0 

    BEGIN
        SET @SQLTableName = (SELECT CHAR(39) + @TableName + CHAR(39))
        SET @LineNum      = CHAR(39) + dbo.[GetabcLine](@TableName) + CHAR(39)
        /*                = (SELECT CHAR (39)+ CASE WHEN REPLACE(RIGHT(@TableName, 2), 'e', '0') = '00'
                                                    THEN '0' 
                                                    ELSE REPLACE(RIGHT(@TableName, 2), 'e', '0')
                                               END
                                                 + CHAR(39))
        */ Requires more sophisticated logic to return 3 char line numbers that includes alphanumeric results
        SET @SQLCmd       = 'UPDATE ' + @TableName + ' ' + '    
                                SET [Job#] = jobs.[mode#]
                                  , [Line] = ' + @LineNum + '
                                  , [StartofJob] = jobs.[start date] 
                                  , [EndofJob] = CASE WHEN jobs.[end date] = GETDATE() THEN NULL ELSE jobs.[end date] END
                                  , [ModelID] = CASE WHEN [ModelID] IS NULL THEN ' + @dent + ' 
                                                     WHEN [ModelID] = ' + @Tnie + ' THEN ' + @ari + ' 
                                                     ELSE [ModelID]
                                                END
                             FROM ' + @TableName + ' hrb ' + '
                             INNER JOIN #Jobs jobs ON hrb.Time1 BETWEEN jobs.[start date] AND jobs.[end date] ' + '
                             WHERE jobs.[line] = ' + @LineNum + ' ' + '
                             AND [Time1] >= DATEADD(DAY,-90, GETDATE())'

EXEC (@SQLCmd)

FETCH NEXT FROM abcTables INTO @TableName

END 

CLOSE abcTables
DEALLOCATE abcTables

DROP TABLE #Jobs

结束

将生产计算机值从一个数据库返回到另一个数据库的另一个sql server的存储过程。目前它已经添加了仅包含两个字符但新生产线的数据,并添加了一个用于识别包含字母数字的3字符行号的附加内容。有什么建议?

sql-server tsql stored-procedures
1个回答
0
投票

听起来您想要将您的功能修改为3个字符后缀的新更改并匹配您的作业表。

dbo.[GetabcLine](@TableName) --==>
SET @LineNum = CASE WHEN REPLACE(RIGHT(@TableName, 3), 'e', '0') = '00'
                                                    THEN '0' 
                                                    ELSE REPLACE(RIGHT(@TableName, 3), 'e', '0')
                                               END

我在我的在线SQL游乐场中包含了您的脚本:https://sqleditor.net/q/BJpRYsHuM

您可以保存您的版本并向我显示有关您的问题的更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.