0
我需要能夠將列添加到將由「用戶」指定的表中。因此,我想知道將表名動態傳遞給存儲過程的樣子。下面是我已經得到的,但不知道下一步該去哪裏。最終,用戶將指定需要「清理」的表名和各個列。要做到這一點,我想添加新的列到表中,然後執行操作。SQL Server:表名作爲存儲過程中的參數
USE *******
GO
CREATE PROCEDURE [dbo].[MS_FormatSectionData](
@SectionCol varchar(50),
@TwpCol varchar(50),
@TWPDirCol varchar(50),
@RangeCol varchar(50),
@RangeDirCol varchar(50),
@ST_CodeCol varchar(50),
@Cnty_CodeCol varchar(50),
@Mer_CodeCol varchar(50),
@Stg_DB varchar(50),
@Tbl_Name varchar(50)
)
AS
BEGIN TRY
DECLARE @sql_AddStgCol VARCHAR(500)
SET @sql_AddStgCol = 'ALTER TABLE' + @Tbl_Name + 'ADD stgSection VARCHAR(3), stgTownship VARCHAR(3),
stgTownshipDir VARCHAR(1), stgRange VARCHAR(3), stgRangeDir VARCHAR(1), stgSt_Code VARCHAR(2), stgCnty_Code VARCHAR(3),
stgMer_Code VARCHAR(3)'
EXEC(@sql_AddStgCol)
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage;
END CATCH
GO
空間你'改變tablesomenameadd' DB引擎解析器需要那些空間。!! – xQbert