資料庫表匯出的excel檔案我給修改了一些資料,現在我想吧這些資料再更新到資料庫表中,讓他們一致,sql server很d疼呀就是匯入進不去,於是乎就寫這麼個儲存過程來簡化一下操作吧。
create proc [dbo].[myproc]
asbegin
begin tran
declare
mycursor cursor for select id,所有需要更新的列名 from
openrowset('microsoft.jet.oledb.4.0','excel
8.0;hdr=yes;imex=2;database=d:\excel檔名.xls',[excel表名$]) --檔案路徑要正確
open mycursor
declare @id int
declare @no nvarchar(20)
while @@fetch_status=0
begin
fetch next from mycursor into @id,@no --或許更多(和上面的列名對應)
begin
update 要更新的表名 set 更新的列名=@no where 主鍵=@id --這裡設定更新條件
endend
close mycursor
if(@@error=0)
begin
commit tran
endelse
begin
rollback tran
enddeallocate mycursor
end
ps:此**執行在sql server 2005
excel匯入資料庫
在你的 中增加一列,利用excel的公式自動生成sql語句 concatenate 函式 具體方法如下 1 增加一列 假設是d列 2 在第一行的d列,就是d1中輸入公式 concatenate insert into table col1,col2,col3 values a1,b1,c1,3 此時...
Excel匯入資料庫
一 在excel中 新建一列,如把列名定為ab,下面放你的資料,比如1,2,3 二 開啟sql企業管理器,右擊你所需要匯入的資料庫,選擇匯入資料,下一步,資料來源選擇microsoft eccel 97 2000,選擇excel檔案繼續下一步,往下按,選擇sheet1 或者2,3 看你把資料放在那一...
excel匯入資料庫
日常工作中,感覺一些基礎知識需要做下筆記,可能是剛畢業的緣故吧,還保持著做筆記的習慣,但根據以往經驗,紙質筆記最多保持一年,過後想找已是難過登天。電子版筆記感覺很不錯,尤其是發布到網路中。筆記內容是本人遇到的感覺可能會有些用的東西,很是瑣碎,記錄在中,僅供學習參考。1 將資料庫中的內容顯示到乙個窗體...