標籤: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在現有資料庫中插入資料