帮助我们,我正在创建一个存储过程,我可以从上传的文件中更新现有表中的一些表行,但是我在更新开始的部分遇到了麻烦。
@sourceTable
=表名#temp1
=已上传的文件代码:
BEGIN
set @refnum = (select refnum from #records where [index] = @index)
set @refnum = replace(@refnum, 'F', '')
-- = '+@refnum+'(courier, stat, statdate, stat2, statdate2, stat3, statdate3, recvby, rel, pupdate)
set @sql = '
UPDATE ' + @sourceTable + '
SET ' + @sourceTable + '.courier = t2.dbo.fn_Parsename(WHOLEROW,''|'', 1),
'+@sourceTable+'.stat = t2.dbo.fn_Parsename(WHOLEROW,''|'',3),
'+@sourceTable+'.statdate = t2.dbo.fn_Parsename(WHOLEROW,''|'',4),
'+@sourceTable+'.stat2 = t2.dbo.fn_Parsename(WHOLEROW,''|'',5),
'+@sourceTable+'.statdate2 = t2.dbo.fn_Parsename(WHOLEROW,''|'',6),
'+@sourceTable+'.stat3 = t2.dbo.fn_Parsename(WHOLEROW,''|'',7),
'+@sourceTable+'.statdate3 = t2.dbo.fn_Parsename(WHOLEROW,''|'',8),
'+@sourceTable+'.recvby = t2.dbo.fn_Parsename(WHOLEROW,''|'',9),
'+@sourceTable+'.rel = t2.dbo.fn_Parsename(WHOLEROW,''|'',10),
'+@sourceTable+'.pupdate = t2.dbo.fn_Parsename(WHOLEROW,''|'',11),
FROM baseTable '+@sourceTable+'
INNER JOIN tempTable #temp1 ON baseTable.refdate + baseTable.refdate = tempTable.dbo.fn_Parsename(WHOLEROW,''|'',0)
WHERE baseTable.refdate + baseTable.refdate = tempTable.dbo.fn_Parsename(WHOLEROW,''|'',0)
SELECT
dbo.fn_Parsename(WHOLEROW,''|'',1),
dbo.fn_Parsename(WHOLEROW,''|'',3),
dbo.fn_Parsename(WHOLEROW,''|'',4),
dbo.fn_Parsename(WHOLEROW,''|'',5),
dbo.fn_Parsename(WHOLEROW,''|'',6),
dbo.fn_Parsename(WHOLEROW,''|'',7),
dbo.fn_Parsename(WHOLEROW,''|'',8),
dbo.fn_Parsename(WHOLEROW,''|'',9),
dbo.fn_Parsename(WHOLEROW,''|'',10),
dbo.fn_Parsename(WHOLEROW,''|'',11)
'
select @sql
print @sql
--exec (@sql)
SELECT 'File has been successfully uploaded', @fileDate,'success' as msg
set @index = @index + 1
END