2010年6月27日 星期日

SQL Server MINUS and INTERSECT

SQL Server 2005 後,提供EXCEP 和INTERSECT, 功能和ORACLE的MINUS, INTERSECT相同

EXCEP 找出存在於第一個子集,但不存在於第二個子集的筆數
INTERSECT 找出皆存在於二個子集中的筆數

這二個方法很方便查找有多個欄位的二個子集差異


以下是SQL 2008 ONLINE HELP說明
ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/b1019300-171a-4a1a-854f-e1e751de3565.htm

The following query returns any distinct values that are returned by both the query on the left and right sides of the INTERSECT operand.

USE AdventureWorks;
GO
SELECT ProductID
FROM Production.Product
INTERSECT
SELECT ProductID
FROM Production.WorkOrder ;
--Result: 238 Rows (products that have work orders)


The following query returns any distinct values from the query to the left of the EXCEPT operand that are not also found on the right query.

USE AdventureWorks;
GO
SELECT ProductID
FROM Production.Product
EXCEPT
SELECT ProductID
FROM Production.WorkOrder ;
--Result: 266 Rows (products without work orders)

以前沒有這種比較的需求, 也沒想過會有EXCEPT,INTERSECT這種語法想了一下,使用left outer join , right outer join  ,inner join 或exists 可以做出同樣的結果嗎???

簡單的測試....., select 的欄位中,含有NULL 值, 則預期結果大不相同

--測試資料
select * into #test1 from
(select  'A11' as col1 , cast(null  as varchar(10))  col2 ,'A31'  col3
union all
select 'A21', null ,'A33'
) a
select * into #test2 from
(select  'A11' as col1 , 'A12'  col2 ,'A31'  col3
union all
select 'A21', null ,'A33'
) a

--EXCEPT
select * from #test1
except
select * from #test2

--回傳結果找出一筆不同
--col1    col2    col3
--A11    NULL    A31

--LEFT OUTER JOIN
select *
from #test1 a left outer join #test2  b
   on a.col1 = b.col1
and a.col2 = b.col2
and a.col3 = b.col3

--回傳結果找出二筆 ,若過濾 掉 b.col1 is null, 則無符合筆數
--A11    NULL    A31    NULL    NULL    NULL
--A21    NULL    A33    NULL    NULL    NULL

轉貼 SQL Server Hints

MSSQLTIPS
Using Hints To Test Indexes in SQL Server

強迫使用某一index查看查詢效能變化, 主要是觀察execution plan 中, query cost是否有顯著的下降

使用方式:

SELECT NationalIDNumber
FROM HumanResources.Employee
WITH (INDEX (PK_Employee_EmployeeID))
WHERE Title = 'Stocker'

2010年6月24日 星期四

安裝 SQL Server 2008 R2 的硬體和軟體需求

唉......
永遠都搞不清楚微軟各項產品的版本適合安裝在什麼樣的作業系統

關於SQL SERVER 2008 R2 各版本可安裝的作業系統,可參考 MSDN 說明

我關注這點

SQL Server 2008 R2 Enterprise (64 位元) x64
處理器類型:
•最小值:AMD Opteron、AMD Athlon 64、具有 Intel EM64T 支援的 Intel Xeon、具有 EM64T 支援的 Intel Pentium IV

處理器速度:
•最小值:1.4 GHz
•建議值:2.0 GHz 以上

作業系統
Windows Server 2003 SP2 64 位元 x64 Datacenter
Windows Server 2003 SP2 64 位元 x64 Enterprise
Windows Server 2003 SP2 64 位元 x64 Standard
Windows Server 2003 SP2 64 位元 x64 Web
Windows Server 2008 SP2 64 位元 x64 Datacenter
Windows Server 2008 SP2 64 位元 x64 Datacenter (不含 Hyper-V)
Windows Server 2008 SP2 64 位元 x64 Enterprise
Windows Server 2008 SP2 64 位元 x64 Enterprise (不含 Hyper-V)
Windows Server 2008 SP2 64 位元 x64 Standard
Windows Server 2008 SP2 64 位元 x64 Standard (不含 Hyper-V)
Windows Server 2008 SP2 64 位元 x64 Web
Windows 2008 R2 64 位元 x64 Datacenter
Windows 2008 R2 64 位元 x64 Enterprise
Windows 2008 R2 64 位元 x64 Standard
Windows 2008 R2 64 位元 x64 Web
Windows Server 2008 R2 x64 for Windows Essential Server Solutions

關於SQL Server 2008 R2各版本提供的功能差異,請參考MSDN說明

版本真夠多的。。。。 

2010年6月21日 星期一

tar指令

windows telnet 環境下,無法使用zip指令
切換回ssh 模式,改用tar來產生壓縮檔

tar -cvf filename.tar file.bak

其中 filename.tar 為要產生的壓縮檔名
file.bak 為被壓縮的原始檔名

AS 2000 ,KB 901200

利用OPENQUERY執行Analysis Server 2000 MDX select 時,會有類似下列的錯誤訊息

伺服器: 訊息 7358 層級 16,狀態 1 行 1



無法執行查詢。OLE DB 提供者 'MSOLAP' 未提供適當的介面來存取文字、 ntext 或 image 資料行 '[MSOLAP] [儲存] 儲存區 [縣/市] [MEMBER_CAPTION]'。


OLE DB 錯誤追蹤 [非介面時發生錯誤: 無法取得儲存體介面 BLOB 的資料行: ProviderName = 'MSOLAP' 表格名稱 = '[MSOLAP]' ColumnName = ' [儲存] 儲存區 [縣/市] [MEMBER_CAPTION] ']。

詳細內容參考 KB 901200, http://support.microsoft.com/kb/901200

如KB所言,此問題在 安裝 Microsoft SQL Server 2000 Service Pack 4 (SP 4) 之後會發生

更新後SQL2000版本為
Microsoft SQL Server  2000 - 8.00.2148 (Intel X86)   Jul  7 2005 20:33:10   Copyright (c) 1988-2003 Microsoft Corporation  Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)

2010年6月8日 星期二

SSIS dtexec 參數指令

dtsexec /?
command line 列出常用的選項

選項不區分大小寫。連字號 (-) 可以用來取代斜線 (/)。
/Conf[igFile]       Filespec (把同一個project會用到的設定都維護在.dtsConfig)
/De[crypt]          Password (package設EncryptSensitiveWithPassword,執行時再指定解密密碼)
/F[ile]             Filespec 
/Set                PropertyPath;Value


my command line:

DTEXEC /FILE "C:\Test.dtsx" /DECRYPT "test2010" /CONFIGFILE "C:\test.dtsConfig"   /SET "\package.variables[gsGuid].Value";"54A2A383-28A6-4227-AA9F-21A8BDFEB853" /SET "\package.variables[gsType].Value";"typeI"




其中,gsGuid是用來寫入sql server uniqueidentifier欄位, 試了一下, 參數前後加大括弧也OK


DTEXEC /FILE "C:\Test.dtsx" /DECRYPT "test2010" /CONFIGFILE "C:\test.dtsConfig"   /SET "\package.variables[gsGuid].Value";"{54A2A383-28A6-4227-AA9F-21A8BDFEB853}" /SET "\package.variables[gsType].Value";"typeI"

不過.....如果這個gsGuid值,要同時給不同DB使用, 則在傳入時,就不要傳入有加大括弧的參數值,以免非SQL SERVER DB資料庫寫入時,發生截斷的問題....因為長度就會超過varchar(36)了.







SSIS 字串轉型成GUID

在SSIS dataflow task 的 drived column  ,將字串轉型為GUID時,前後要加大括弧

(DT_GUID)("{" + @[User::gsGuid] + "}")

2010年6月7日 星期一

SSRS 造字匯出pdf

報表內容含造字(EUDC,End-User Defined Characters), 匯出EXCEL都沒問題
唯獨匯出pdf不成功

試了RS designer 的三個版本
RS 2000 designer ,造字preview 與匯出EXCEL正常,匯出PDFOK , 但造字變成 !
RS2005 designer , 造字preview 與匯出EXCEL正常,匯出PDFOK, 但造字變成口
RS2008 designer , 造字preview 變成口, 但匯出EXCEL造字顯示正常,
匯出PDF時, 出現以下訊息
 ---------------------------
Export Error
---------------------------
An error occurred during local report processing.
CreateFontPackage failed: Win32 error:1006

也試用了ASPOSE的 Aspose.Pdf for Reporting Services, 造字仍無法顯示

最後試了, VS2010 report viewer. 造字preview 與匯出EXCEL與WORD正常,匯出PDFOK, 但造字變成口
 
OO, 目前看來是無解

2010年6月1日 星期二

Dos command 開啟網芳

這個服務關掉後,AS 2000就無法使用DSO連線
所以每個月在產生新的partition時,要先把這個服務給開起來,然後做完partition creation後,再關閉這個服務
當然啦, 一定要用具olap administrators的domain user登入來執行partition creation才行喔

sc config LanmanServer start= auto


net start LanmanServer


net stop LanmanServer /Y

sc config LanmanServer start= disabled

DOS command 取國曆年月

首先先參考SS64的方法,取得系統日期
雖然看不太懂...但模仿一下也是OK的啦,能取得我要的國曆年月就好

@echo off&SETLOCAL
:: This will return date into environment vars
:: Works on any NT/2K/XP machine independent of regional date settings
:: 20 March 2002
FOR /f "tokens=1-4 delims=/-. " %%G IN ('date /t') DO (call :s_fixdate %%G %%H %%I %%J)
goto :s_print_the_date
:s_fixdate
if "%1:~0,1%" GTR "9" shift
FOR /f "skip=1 tokens=2-4 delims=(-)" %%G IN ('echo.^date') DO
 (set %%G=%1&set %%H=%2&set %%I=%3)
goto :eof
:s_print_the_date
set /a yy=%yy%-1911
set /a ym=%yy%%mm%

echo Month:[%mm%] Day:[%dd%] Year:[%yy%] YM:[%ym%]
ENDLOCAL&SET mm=%mm%&SET dd=%dd%&SET yy=%yy%

以上,紅字部份是我要的國歷年月囉...

publish error allowDefinition='MachineToApplication'

一個老舊的aspx web form專案,調了一些功能建置成功,但進行部署時顯示以下錯誤。 在應用程式層級之外使用註冊為 allowDefinition='MachineToApplication' 的區段發生錯誤。錯誤的原因可能是虛擬目錄尚未在 IIS 中設定為...