วันอังคารที่ 7 กรกฎาคม พ.ศ. 2558

SSIS Checkpoint File Object Type issue with complex data types

What the BUG????

SSIS  2014 , Visual Studio 2013 Update 4

ปัญหาของ Checkpoint file ที่ set ใน Package กรณีมี varible ประเภท Object ก่อให้เกิดปัญหาซึ่งยังหาสาเหตุไม่เจอ

PackageA : มีกระบวนการทำงานซึ่งมีการ Execute SQL Task เก็บ Result set ไว้ในตัวแปรประเภท OBJECT แล้วนำไป Fetch ใน For each loop container ซึ่งก็ทำงานได้ดี โดยมี Fetch data ถึง 2 รอบ

ซึ่งทำงานได้ปกติ

แต่เมื่อมีการ Add new task ขึ้นมาก่อนหน้า แล้วทำการ Execute SQL & Fetch data กลับไม่สามารถ Fetch data ออกมาได้ ทำอย่างไรก็จะได้ค่า 0 record จากการ fetch

ทดสอบแก้ปัญหาหมดทุกอย่าง จนมาเจอว่าเมื่อลองปิดการใช้งาน Checkpoint file ปรากฏว่าสามารถ Fetch data ออกมาได้อย่างถูกต้อง


ปวดหัว! WTF

วันพุธที่ 1 กรกฎาคม พ.ศ. 2558

MDX Query : Query dimension member only

Some time you may want to check or validate dimension members only.
You don't need to process cube.

The syntax is very simple

SELECT {} ON 0,
{[Dim_Customer].[Customer_ID].Members } ON 1
FROM [$Dim_Customer]


Compare to Cube

FROM [Cube_Name] ---> Change cube name format to FROM [$Dim_Name]

"$" Using dollar sign for dimension name




วันศุกร์ที่ 16 มกราคม พ.ศ. 2558

SSIS Tips

---- Data flow : Error rows redirect.
ตัวอย่าง Table customer มี 1000 records โดยมี CUST_CODE = PK
Import data จาก Text file 100 รายการ
มี 5 รายการที่มี CUST_CODE ซ้ำกับของเดิม

** Concern
  - Default ของ "Data acess mode"  (Destination) คือ  "Table or view - fast load"
    ถ้าเป็นตัวเลือกนี้ ทั้ง 100 รายการจะถูกมองว่า Error ทั้งหมด ซึ่งทำให้ยากต่อการวิเคราะห์ว่า Record ใด Error

   ดังนั้นกรณีที่ต้องการให้มีเฉพาะ 5 รายการที่ซ้ำ Redirect row ไปเก็บไว้ใน Error log table ให้เปลี่ยน Mode เป็น "Table or view"

Credit : http://stackoverflow.com/questions/5172801/bids-ssis-redirect-row-on-error-sends-too-many-rows





-----Inferred Dimension members
สรุปย่อๆคือ การสร้างรายการข้อมูลของ dimension ขึ้นมากลางอากาศขณะโหลด Fact table
เช่น Fact_sale มี Product ใหม่ แต่ใน dim_product ยังไม่มี Record ก็สร้าง Record ใน dim_product เลย
แล้วเอาไป insert in fact_sale โดยมี Flag ใน dim_product บอกว่า Record นั้นๆเป็น Inferred หรือไม่ (Boolean) แล้วค่อยมา Update ข้อมูลอื่นๆภายหลัง

แต่ขั้นตอนการ Implement ก็ซับซ้อนขึ้นด้วย

Credit : http://www.sqlservercentral.com/articles/Data+Warehouse/71233/

วันศุกร์ที่ 7 พฤศจิกายน พ.ศ. 2557

Migrate SSIS 2005 to SSIS 2014 via Visual Studio 2013

SSIS Package can be upgrade by VS 2013 in vizard .

In case of package store password , you can set password to all package by select all package you want and type password in a box and apply to all.



ORACLE Connect 
There are many concern about connect oracle.

Software require (Oracle)
   Oracle_win32_11gR2_client   --> For dev environment
   Oracle_win64_11gR2_client    --> For Server
   If you want to use SQL Developer you need to install Java (32bit)
   Download Java : jdk-7u71-windows-i586
*** IMPORTANT --  (Installation Type: Administrator)

NLS_LANG
should be AMERICAN_AMERICA.WE8MSWIN1252
In my case NLS_LANG has set default to THAI_THAILAND.TH8TISASCII  that's not working!


SSDT (SQL Server Data Tools) 
In SQL Server 2005,2008,2008R2 we know the Business Intelligence Solution .
Since SQL Server 2012 Microsoft has change the way to design solution to be SSDT
Download SSDThttp://www.microsoft.com/en-us/download/details.aspx?id=42313


------------------- Latest Update ---------------------

Package update
-- 2005 -->2014 ต้องใส่รหัสผ่านตอน Update
--Data source sql server เปลี่ยน type จาก     Native OLE DB เป็น SQL Server Native Client 11.0
--Require ORACLE Client ขอโน๊ตมาลง
  ตอน install ให้เลือก custom เพื่อเลือก sql plus และ Connection manager / Net client
--Not success , Stuck at 80%

******ลง แบบ Admin จะได้จบๆเรื่อง


Oracle Base --> C:\Oracle\Home

Software Location --> C:\Oracle\Home\product\11.2.0\client_1


-- Path variable value --
C:\Oracle\bin;C:\Oracle;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOTxxx

วิธีจัดการ Warning - Error ตอน Install Oracle Client
http://dba.stackexchange.com/questions/50867/environment-varible-path-exceeding-recommended-length-solution
คือเปิด system variable -- Path -- ลบให้เหลือสั้นๆ กด OK จากนั้น Start install ใหม่ ทำเสร็จ Set ให้เหมือนเดิม


--Path value หลังจาก Install เสร็จ
C:\Oracle\Home\product\11.2.0\client\bin;C:\Oracle;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine xxxx

C:\Oracle\Home\product\11.2.0\client\bin;C:\Oracle;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOTxxx

-- ลง 32 Bit เสร็จแล้วสามารถใช้งานได้ โดยเลือก
 Native OLE DB\Oracle Provider for OLE DB


-- ขั้นตอนการแก้ SSIS Package

Souce (Oracle) --> Change defaultCodePage -->TRUE
Data Type --> Unicode string[DT_WSTR]


-- การ Create database เพื่อทดสอบ มีerror
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file
ให้ Set permission ให้ everyon สามารถ write
-- ต้องแก้ Compat ให้ >=100 , 90 ไม่ผ่าน
SET COMPATIBILITY_LEVEL = 100



---------- NLS LANG ตอน Design package มีส่วนสำคัญ ต้อง set เป็น AMERICAN ถ้าเป็น THAI --> Error
THAI_THAILAND.TH8TISASCII
AMERICAN_AMERICA.WE8MSWIN1252



--------- SCRIPT TASK
Need to install VSTA Microsoft (Visual Studio Tools for Applications 2012 SDK)
-->Set default language of Script task
   Tool->Option->Business Intelligence Designer->Integration Service
      -->Chage Script langage to VB



-------- Excel source
Need to install  (x86 on designer Machine)
AccessDatabaseEngine_x86-NeedtoInstall.exe




---- CARD Reward Balance ที่มีปัญหา
  --->Script shoud chage to Merge instead of Inset if not exist








วันอังคารที่ 28 พฤษภาคม พ.ศ. 2556

How to clear index (aggregation file) from you Cube or partition

Using  ProcessClearIndexes 
ปกติแล้วใน UI (SSMS) จะไม่มี Option นี้ให้เลือกใช้
แต่สามารถใช้ได้โดยการใช้ Script แทน


Credit by :
http://searchsqlserver.techtarget.com/tip/Recommended-practices-for-SQL-Server-Analysis-Services-aggregations


วันอังคารที่ 9 ตุลาคม พ.ศ. 2555

Sql server , Summary accumulate , running total



I prefer  the second and the third sulution

Solution 2: The "Celko" Solution

(NoIndex = 25 secs, Index = 20 secs)
SELECT DayCount,
       Sales,
       Sales+COALESCE((SELECT SUM(Sales) 
                      FROM Sales b 
                      WHERE b.DayCount < a.DayCount),0)
                         AS RunningTotal
FROM Sales a
ORDER BY DayCount



Solution 3: The "Guru's Guide" Solution

(NoIndex = 38 secs, Index = 17 secs)
SELECT a.DayCount,
       a.Sales,
       SUM(b.Sales)
FROM Sales a
CROSS JOIN Sales b
WHERE (b.DayCount <= a.DayCount) AS RunningTotal
GROUP BY a.DayCount,a.Sales
ORDER BY a.DayCount,a.Sales


วันศุกร์ที่ 28 กันยายน พ.ศ. 2555

MDX Dynamic Hierarchy 1


ตัวอย่างการทำ Dynamic Hierarchy กับ Calculate member
LEVELS ใช้ Function นี้ในการ Convert string เป็น Hierarchy LEVEL ได้
MEMBERS  ใช้ Function นี้ในการ Convert string เป็น Member (CurrentMember) ได้ด้วย

With member [Measures].[HRC] as
"[Dim_Date].[HRC_YQMD]"

MEMBER [Measures].[AccmCash] as
    Aggregate(
          PERIODSTODATE(
            LEVELS([Measures].[HRC]+".[Year]"),-- CONVERT String to LEVEL
            MEMBERS([Measures].[HRC]+".CURRENTMEMBER") -- CONVERT String to MEMBER
          ),[Measures].[Cash])


SELECT {[Measures].[Cash],[Measures].[AccmCash]} ON 0,
NON EMPTY
[Dim_Date].[Hrc_YQMD].[Date].MEMBERS ON 1
FROM (SELECT [Dim_Date].[Month].&[201201] ON 0 FROM [Cube_Txns])

RESULT
Date                  CASH            ACCMCASH

20120101 44,176,675 44,176,675
20120102 46,656,659 90,833,334
20120103 43,954,618 134,787,952
20120104 46,481,631 181,269,583
20120105 45,993,021 227,262,603
20120106 43,674,555 270,937,158
20120107 40,730,331 311,667,489
20120108 37,520,953 349,188,442
20120109 41,457,006 390,645,448
20120110 41,601,764 432,247,212




วันพุธที่ 26 กันยายน พ.ศ. 2555

Excel & OLAP Pivot table


การสร้าง Pivot table จาก OLAP ใน MS Excel

1. Connection ที่สร้างใหม่จะเป็นไฟล์อยู่ในเครื่อง Computer นั้นๆ
2. Connection ที่สร้างไว้แล้วสามารถ Reuse ได้
3. ใน Excel work book สามารถอ้างถึง Connection ในเครื่อง Computer ที่สร้างไว้ได้
  3.1 โดย default , Excel จะ Copy connection string จาก Connection file ในเครื่อง computer มาไว้ใน Work Book
  3.2 เราสามารถเลือก Option ให้ Excel link connection จาก Connection file ในเครื่อง Computer ได้
  3.3 โดย default , Excel จะไม่ save password ไว้ใน Connection string ที่ Copy มาไว้ใน Workbook ต้องคลิ๊กเลือก Save passord เอง

4. Connection ใน Excel work book สามารถถูกอ้างถึงจาก Pivot table หลาย pivot ได้
   4.1 การ Refresh pivot table ใดๆ จะทำการ Refresh Connection ที่ pivot table นั้น Refer ไปถึง ไม่ใช่แค่เพียง Refresh เฉพาะ Pivot table นั้นๆ
   4.2 หาก 1 Connection มี Pivot table หลาย pivot อ้างถึง   การ Refresh connection นั้นๆ จะทำการ Refresh ทุก Pivot table ที่อ้างถึง Connection ที่ Refresh
   4.3 ดังนั้น การที่เราเข้าใจว่าจะ Refresh เฉพาะ Pivot table ที่ต้องการนั้นไม่จริง  เพราะหาก Connection ที่ Pivot Refer มี Pivot table อื่นๆอ้างถึงอยู่ด้วย  ทุก Pivot table ที่อ้างถึง Connection นั้นจะถูก Refresh ทั้งหมด

5. ข้อแนะนำสำหรับการสร้าง Pivot table ใน Work book
   5.1 หาก Pivot table แต่ละ pivot ที่สร้างขึ้น ใช้เวลานานในการ Refresh Data ควรสร้าง Connection ใน Work book แยกกันเพราะเวลา Refresh จะได้ไม่กระทบกับ Pivot อื่นๆ
   5.2 Pivot table ที่สามารถ Refresh Data ได้รวดเร็วสามารถใช้ Connection เดียวกันได้



SSAS Cube processing tips.

วิธีการประหยัดเวลาในการ Process OLAP Cube ที่มีปริมาณข้อมูลเยอะมากๆ
ในกรณีที่อยู่ระหว่างการแก้ไข หรือตรวจสอบความถูกต้องของข้อมูลใน CUBE
การ Process FULL เป็นตัวเลือกที่ไม่ดีสำหรับกรณีใดๆที่มีข้อมูลเยอะมากๆ
เนื่องจากหากมี Error ใดๆ จำให้การ Process failed ทั้งหมด
ดังนั้นคำแนะนำคือ ทำการ Process Object ตามลำดับขั้นดังนี้

1 Process Full Dimension 
เพื่อตรวจสอบความถูกต้องของ Dimension ต่างๆ ทั้งข้อมูลใน Dimension และ Hierarchy รวมถึงการ Set Attribute relationship

2 Process Cube Structure
เพื่อทำการ Build structure ทั้งหมดของ CUBE ซึ่งการ Process นี้จะทำการล้างข้อมูลทั้งหมดที่มี (หาก Set storage mode = MOLAP) แต่จะทำให้สามารถ Browse cube ได้เหมือนกับ Process Full เพียงแต่ไม่มีข้อมูลแสดงเท่านั้นเอง

3 Process Data 
สามารถ Process Measure Group และ Partition ภายใต้ Measure Group
เพื่อทำการ Add ข้อมูลเข้าระบบ ทั้งนี้ ควรทดสอบ Process data ใน Partition บางส่วนก่อนเพื่อตรวจสอบความถูกต้องของข้อมูล เพราะหากมีการ Re-Design dimension และทำ Attribute relation ship ผิดใน Dimension design จะส่งผลกับข้อมูลผิดตามไปด้วย

4 Process Index
เพื่อ Process aggregation ของ CUBE ซึ่งส่วนนี้ขึ้นอยู่กับการ Design aggregate ใน Cube partition

โดยขั้นตอนลำดับขั้นที่กล่าวมาเป็นวิธีการที่ช่วยลดเวลาในการ Process Cube เพื่อตรวจสอบ
หรือสามารถ apply ได้ในหลายกรณีครับ


วันอังคารที่ 21 สิงหาคม พ.ศ. 2555

sql server update record , percent complete

กรณี Update ข้อมูลจำนวนมาก
หากต้องการรู้ว่า การ update นั้น เสร็จไปแล้วกี่เปอร์เซ็นต์

SELECT * FROM sys.dm_exec_requests WHERE session_id = 68
See column percent_complete




Credit
http://www.mssqltips.com/sqlservertip/1338/finding-a-sql-server-process-percentage-complete-with-dmvs/

วันอังคารที่ 10 กรกฎาคม พ.ศ. 2555

SQL Server list Database file name


select d.name as db_name, f.name as file_name, f.filename as logical_filename
from sysaltfiles f
inner join sysdatabases d
on (f.dbid = d.dbid)
order by 1,2


Restart OLAP Service from SSIS package

Reference from http://businessintelligencechronicles.blogspot.com/2009/02/using-ssis-script-task-to-executing.html


Using script task to connect remote server to stop & start mssqlserverOLAPService
Basicly we know command to stop and start olap service via command prompt.

Start -->Run command
Net stop mssqlserverOLAPService   <---- Command to stop
Net start mssqlserverOLAPService   <---- Command to start

In the example he remote to run Calc.exe via Command variable
In my case I create two string Command (Command1 , Command2)
Set Command1 = Net stop mssqlserverOLAPService
Set Command2 = Net start mssqlserverOLAPService


And then seperate  commands into 2 script tasks
1 = Script for stop
2 = Script for start

**Remark If  you SSIS version is 2008 You no need to change anythings except your command.
If you using  SSIS 2005 you need to change a little bit command
from Dts.TaskResult = ScriptResults.Success to be Dts.TaskResult = Dts.result.Success
That's it.



That's work perfectly!!!
Thanks 

วันเสาร์ที่ 7 กรกฎาคม พ.ศ. 2555

วันพุธที่ 4 กรกฎาคม พ.ศ. 2555

OLAP Distinct count measures

Analysis Services Distinct Count Optimization

Refer to : 

http://sqlcat.com/sqlcat/b/technicalnotes/archive/2010/09/20/analysis-services-distinct-count-optimization-using-solid-state-devices.aspx


วันศุกร์ที่ 22 มิถุนายน พ.ศ. 2555

View percentage for SQL task

SELECT percent_complete , (estimated_completion_time/1000)/60 Estimated_completion_time_Mins ,
 (total_elapsed_time/1000)/60 Total_Elapsed_Time_Mins ,DB_NAME(Database_id) DBName ,*
FROM sys.dm_exec_requests
WHERE percent_complete <> 0


วันจันทร์ที่ 18 มิถุนายน พ.ศ. 2555

SQL Server 2008R2 Change server collation

วิธีการเปลี่ยน Server Collation ของ SQL Server 2008 R2
ในกรณีที่ตอน Install ไม่ได้เลือก Collation ของ Server ให้เป็นไปตามต้องการ
(โดยปกติแล้ว Server จะ Default เป็น SQL_Latin bla bla bla)

1 หา setup.exe ใน Path ที่ Install SQL Server เช่น
  C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\SQLServer2008R2\
  หรือจาก Media Path ที่มี setup.exe อยู่ เช่น
   D:\SQL2008R2
2 run command window. เพื่อจะใช้คำสั่งผ่าน Command line.
3 จัดการรัน command ตามนี้
   setup.exe /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLCOLLATION=Thai_CI_AI /SQLSYSADMINACCOUNTS="WIN2008BI\SQLadmin" /SAPWD="myP@ss"

ข้อควรระวังตรงนี้คือ User ที่จะใช้ในการรันจะเป็น Window user ไม่ใช่ sa ของ SQL Server น่ะ
จากตัวอย่างคือ "WIN2008BI" = Server Name , SQLadmin = Account , และ SAPWD = "myP@ss" คือ Password ในการ Login เข้า Window


---------------------------
ERROR LOG กรณีใส่ parameter ผิด

Log file สามารถเข้าไปดูได้ที่

C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log

Summary.txt คือไฟล์สรุป Log สามารถดูที่บรรทัดสุดท้ายว่ามี Exception หรือไม่ ถ้ามีแสดงว่าการ Setup ไม่ผ่าน อาจจะมีข้อผิดพลาดจากเรื่อง User / Password หรืออื่นๆ ให้อ่านในส่วน Exception นี้

ตัวอย่าง

Exception summary:
The following is an exception stack listing the exceptions in outermost to innermost order
Inner exceptions are being indented

Exception type: Microsoft.SqlServer.Chainer.Infrastructure.InputSettingValidationException
    Message:
        The Windows account ”W28BI401\sos” does not exist and cannot be provisioned as a SQL Server system administrator.
    Data:
      SQL.Setup.FailureCategory = InputSettingValidationFailure
      DisableWatson = true
    Stack:
        at Microsoft.SqlServer.Chainer.Infrastructure.InputSettingService.LogAllValidationErrorsAndThrowFirstOne(ValidationState vs)
        at Microsoft.SqlServer.Configuration.SetupExtension.ValidateFeatureSettingsAction.ExecuteAction(String actionId)
        at Microsoft.SqlServer.Chainer.Infrastructure.Action.Execute(String actionId, TextWriter errorStream)
        at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.ExecuteActionHelper(TextWriter statusStream, ISequencedAction actionToRun)
    Inner exception type: Microsoft.SqlServer.Configuration.SqlEngine.ValidationException
        Message:
                The Windows account ”win2008BI\SQLadmin” does not exist and cannot be provisioned as a SQL Server system administrator.



ข้อควรระวังเกี่ยวกับ Account Name  , IT CASE SENSITIVE ตัวเล็กตัวใหญ่มีผลครับ - -"
เช่น WIN2008BI แตกต่างจาก win2008BI
ถ้า server name จริงเป็นตัวใหญ่หมดก็ต้องใช้ตัวใหญ่ทั้งหมดใน parameter ไม่งั้นมันก็บอกว่าไม่มี Account นั้น ฮ่าๆ

ขอให้เปลี่ยน Collation สำเร็จนะครับ :)
  



 

วันพุธที่ 13 มิถุนายน พ.ศ. 2555

Process INDEX Error , Code 3238133761


<return xmlns="urn:schemas-microsoft-com:xml-analysis">
  <results xmlns="http://schemas.microsoft.com/analysisservices/2003/xmla-multipleresults">
    <root xmlns="urn:schemas-microsoft-com:xml-analysis:empty">
      <Exception xmlns="urn:schemas-microsoft-com:xml-analysis:exception" />
      <Messages xmlns="urn:schemas-microsoft-com:xml-analysis:exception">
        <Error ErrorCode="3238133761" Description="File system error: The following error occurred while opening the file '\\?\F:\TSC Projects\OLAP\Data\olap_tsc401.76.db\Cube_TXNs.108.cub\Txns Terminal.0.det\Fact TXNs Y200812.0.prt\6.string.data'." Source="Microsoft SQL Server 2005 Analysis Services" HelpFile="" />
        <Error ErrorCode="3238133761" Description="File system error: The following error occurred while opening the file '\\?\F:\TSC Projects\OLAP\Data\olap_tsc401.76.db\Cube_TXNs.108.cub\Txns Terminal.0.det\Fact TXNs Y200812.0.prt\6.string.data'." Source="Microsoft SQL Server 2005 Analysis Services" HelpFile="" />
        <Error ErrorCode="3240034325" Description="Errors in the OLAP storage engine: An error occurred while processing the indexes for the Fact TXNs Y200812 partition of the TID measure group of the Cube_TXNs cube from the olap_tsc401 database." Source="Microsoft SQL Server 2005 Analysis Services" HelpFile="" />
        <Error ErrorCode="3239837698" Description="Server: The operation has been cancelled." Source="Microsoft SQL Server 2005 Analysis Services" HelpFile="" />
      Messages>
    root>
  results>
return>


ยังหาสาเหตุไม่ได้ แต่คาดว่าน่าจะเกิดจาก Memory ไม่พอขณะทำการ Restore OLAP Database


วันพฤหัสบดีที่ 24 พฤษภาคม พ.ศ. 2555

Using DMV in SQL 2008 for finding informations

http://www.sqlsoldier.com/wp/sqlserver/usingsystemrestrictschemafunctioninmdxtoquerydmvs


Key words = DMV , SQL 2008

Combine CSV files via dos command

Open command prompt.

Type copy c:\*.csv c:\combine.csv and press enter

This will combine all of the csv files that are in your root c:\ directory into one file called File.csv.

You can change the file names and paths as necessary.