Sqlserver在現有資料庫中插入資料

來源:互聯網
上載者:User

標籤:long   blog   cat   select   函數   字典   box   csharp   el函數   

需求:1.客戶提供的excel表和資料庫中的表結構總是有一些差距,id的產生,各種欄位的關聯等等

        2.

 如何在Excel中產生Guid。

1.在Excel的宏中執行以下代碼:

Private Declare PtrSafe Function CoCreateGuid Lib "ole32" (id As Any) As Long    Private Function CreateGUID() As String                  Dim id(0 To 15) As Byte                  Dim Cnt As Long, GUID As String                  If CoCreateGuid(id(0)) = 0 Then                          For Cnt = 0 To 15                CreateGUID = CreateGUID + IIf(id(Cnt) < 16, "0", "") + Hex$(id(Cnt))            Next Cnt                          CreateGUID = Left$(CreateGUID, 8) + Mid$(CreateGUID, 9, 4) + Mid$(CreateGUID, 13, 4) + Mid$(CreateGUID, 17, 4) + Right$(CreateGUID, 12)                  Else                          MsgBox "Error while creating GUID!"                      End If              End Function

 2.寫一些Excel函數去找對應的關係。

=IF(ISNA(VLOOKUP($O3,域字典!A:B,2,FALSE)),"NULL",VLOOKUP($O3,域字典!A:B,2,FALSE))

 3.把excel中的資料拷貝到資料庫中。

思路:1.根據一些特定列判斷資料庫中的列是否有重複的

select ‘‘‘‘+min(id)+‘‘‘,‘ from 表名where 列名 in (select  列名 from(select 列名  from 表名where 列名 in (select 列名 from 表名group by 列名having count(*)>1) )as b group by 列名,列名having count(*)>1) group by 列名,列名

 2.去除重複的

delete from 表名 where id in ()

 3.修改資料執行update語句

4.複製表結構

select * into  [dbo].要複製的表  from [dbo].原有的表

 5.刪除資料結構

truncate table 表名

 

Sqlserver在現有資料庫中插入資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.