用以下方法掙扎。 下面是一個屏幕截圖,當我運行下面的查詢 - 外地文件的SUBSTRING查詢更新
select [Journal Source], [File], filepath from xIntegration..FinanceIntegration WHERE FilePath like '%rent debit%'
我所要做的是更新期刊源與_(下劃線)之前的第一個數字。
問題當我運行下面的代碼時,它將所有行的日誌源設置爲9,而不僅僅是我期望的位置。
我會想到的是,前4行會更改爲8,其餘變化到9
--UPDATE THE BATCH NUMBER (Journal Source) For Rent Debit File
DECLARE @filenameRentDebit as varchar(100)
SELECT @filenameRentDebit = [File] FROM FinanceIntegration WHERE FilePath like '%rent debit%'
DECLARE @indexRentDebit INT
set @indexRentDebit = CHARINDEX('_', @filenameRentDebit)
UPDATE FinanceIntegration
SET [Journal Source] = SUBSTRING(@filenameRentDebit, 0, @indexRentDebit)
WHERE FilePath like '%rent debit%'
我在做什麼愚蠢的錯誤?謝謝
這看起來像SQL Server,所以我添加了標籤。 –