SQL Server Management Studio(企業管理器) 手動導入Excel文件,有時間還是非常方便的,省去了寫代碼的麻煩。
具體步驟如下:







下面附上 創建游標的方法(用於循環讀取臨時表中的數據,插入或變更到正式表里去)
--需要賦值的參數 Declare @ItemID int Declare @BudgetValue decimal(18,2) Declare @Month int --有默認值的參數 Declare @UserName nvarchar(50) set @UserName='Administrator' Declare @Year int set @Year=2014--設置年份 Declare @BuId int set @BuId=9 --游標的寫法(用於把臨時表里的數據,插入到數據庫正式表里去) DECLARE TMP_CURSOR CURSOR FOR select * from TempBudget -- 這里寫要查詢的臨時表SQL OPEN TMP_CURSOR FETCH NEXT FROM TMP_CURSOR INTO @ItemID,@BudgetValue,@Month-- 這里填寫 【需要賦值的參數】 WHILE @@FETCH_STATUS =0 BEGIN insert into BUDGET_LINE( BU_ID, BUDGET_YEAR, BUDGET_MONTH, ITEM_ID, BUDGET, ACTUAL_BUDGET, CREATEDBY, UPDATEDBY ) values( @BuId, @Year, @Month, @ItemID, @BudgetValue, 0, @UserName, @UserName ) --這里寫需要操作的SQL語句(可以是 insert\update) FETCH NEXT FROM TMP_CURSOR INTO @ItemID,@BudgetValue,@Month -- 這里填寫 【需要賦值的參數】 END CLOSE TMP_CURSOR DEALLOCATE TMP_CURSOR
