Monday, May 21, 2012

SSIS to XML Destination

I pieced together this solution using comments on other blogs. No one had put it together quite like this, so I decided to post my solution. It works great, is fast and free.

First, write your query in SQL Server Management Studio (SSMS).

Mine was:

select * from[vwAPI-CustomerMaster]
for xml path('CustomerMaster'),root('Customers')

Your  "path" will be the top level object name (one for each row), Your"root" will be the name of the root. If you don't understand this, put in anything and run the file and you will see the values among the first bracketed ( < > ) values.

Here's a sample dummy test of Path and Root:

select * from [vwAPI-CustomerMaster]
for xml path('TweedleDee'),root('TweedleDumb')

 Outputs:

<TweedleDumb>
  <TweedleDee>
    <CUTM>ZTEMPL03<CUTM>
    <CONO>100<CONO>
    <LNCD>GB<LNCD>
    <CUNO>10000000<CUNO>
    <CUNM>M&M Distribution(APMS)<CUNM>
    <CUA1>Unit 11, The Lawn<CUA1>
    <CUA2>Mountmassey<CUA2>
    <CUA3>Macroom<CUA3>
            and so on...
So tweak your sql in SSMS until you get the output you need there. 

Tip: When SSMS gives your results it will look like a single field in a single row. Click on that lonely field and SSMS will let you see your full output.

You can also start with something like this:

select * from [vwAPI-CustomerMaster]
 for xml auto

And use that output if that works for you.
Once you have your source query, go to your Control Flow and pull in an Execute SQL task. Configure the Execute SQL task as shown below.

(click the graphic to see the whole thing)
1) Set the ResultSet to XML.
2) Set the Connection to a connection you've already created. The connection should point to wherever your data for the XML is being stored.
3) In SQL Statement, paste the code you developed in SSMS.
4) Go to the ResultSet Tab.
5) Add a Result.
6) Name it 0 [zero] - not sure why you have to name it that, but you do.
7) Tell the task where to put the Result. In my example, I created a package level variable and called it XMLDataSet. The variable is type STRING (suprised me).
8) Exit out - back to the Control Flow.
On the control flow, add a script task.
The script will be in VB and it is very simple.
1) Set the ScriptLanguage to Visual Basic. If you forget to do this first, the option gets locked down and then you have to delete the script task and create a new one.
2) Add your variable to the ReadOnlyVariables list.
3) Click on the Edit Script button.
4) Scroll down until you see:
  Public Sub Main()      
   '
   
' Add your code here
   
'
   
Dts.TaskResult = ScriptResults.Success 
End Sub
5) Replace that code with this:
Public Sub Main()       
 Dim sw As New IO.StreamWriter("C:\Temp\test.xml")      
 sw.Write(Dts.Variables("User::XMLDataSet").Value.ToString()) 
 sw.Dispose()
 D
ts.TaskResult = ScriptResults.Success
End Sub
6) Replace the two RED values with your own output location and your own variable name. (You can also convert your hard-coded output location to a variable value later).
7) Go to the Menu bar and click on the Build menu. A single item should appear as a candidate for the build action. Choose that. If you have any syntax errors, fix them.
8) Exit out of the Script dialog and return to the Control Flow.

9) Test.

       


Thursday, April 28, 2011

Questions I missed on the 70-448 Exam

I took my first ever Microsoft Cert Exam yesterday. I really had no idea what to expect but I did think it would be easier. I failed. I needed 700. I got 610.

I was able to remember a lot of the things that stumped me. So here's my tail-between-the-legs study list.

1) Lookup how to handle failover for SSIS in a clustered environment. Do I register the App and let the clustering software handle things or do I put checkpoints in every package?

2) How do I implement a referenced Dimension? The only kind of Dim I haven't actually used.
The only kind of dim I would rather never use since I could just do a lookup of the reference key during ETL and add it to the (would-have-been-referenced) Dim table beforehand.

3) The whole thing around the TransactionOption property. Egads. Is that crap ever confusing. I studied this before the exam, but I was hoping to get lucky. Clearly that is not going to happen.

4) Registering a custom Assembly for SSRS.

5) They defined a Named Set using the option of either ParallelPeriod MDX function or PeriodsToDate. I would have approached it totally differently. I went with PeriodsToDate. Did I mess up?

6) Pay closer attention to the options avail using the Profiler tool to track SSAS

7) What the hell is a Dynamic Managed View?

8) User!UserID! in a report header - when run on a Subscription, causes an error? how to overcome. I narrowed it to either "stored credentials" or "service account credentials" - I went with Stored. I think I might have been wrong.

9) Something about Kerberos and SSRS. Unfortunately I had counted on this being like a Jeopardy question where every clue with "Architecture" in the body has the answer of "Who was Frank Lloyd Wright?" -- I was counting on something like "Blah, blah, blah SSRS Security, blah, blah." and I was going to yell "What is Kerberos?" Instead the question asked something like "Which SSRS configuration file will you edit to indicate that you will be using Kerberos?" BOMBED that one I'm sure.


There were a few that I was really, really embarrassed to admit were not easy to me.

1) Something about a parent-child relationship in the DSV and I need to show that relationship in the DSV. I was stumped bc I don't think it's necessary to show that relationship in the DSV ever!! I always define that relationship in the Dimension Attribute type and parent-child dims work like a charm. I have accidently joined a table to itself in the DSV before, but totally by accident. So I was stumped re which key was source and which was destination.

2) There was an SSIS flow where it was supposed to use variables to indicate conditional flows and splits with dashed lines and function symbols. I couldn't remember. In cases like these I have a terrible tendency to go with my gut and test til it works.

So, I had crow for dinner last night and for breakfast this morning...and now I'm back to studying so I can have something a little less bitter for lunch.

Thursday, June 24, 2010

Excel thinks 1900 was a Leap Year, SSIS knows it was NOT


Evidently, the year 1900 is not technically a leap year. See this How Stuff Works article to learn why (if you care).

Well I was trying to import a file with dummy dates that had been created in Excel 2007. The dummy dates had been created automatically and Excel had inserted a Feb 29, 1900.

SSIS knows better. It rejected the invalid Feb 29, 1900 date.

My file was a stop-gap until I got full access to my real data source so I just manually changed the records that were marked Feb 29, 1900. I don't know what you are going to do with your file!

Tuesday, June 22, 2010

Run a Batch File from an SSIS Execute Process Task

Took me a bit of head banging to figure this out so I wanted to share. If you want to run a batch file from an SSIS Execute Process task you do not put the batch file name as the Executable property (though I think that seems to most logical at first blush). Instead you put cmd.exe as the Executable and pass the name and location of your batch file in as an argument.

Saturday, February 13, 2010

Agile Design Documentation with SSIS

So I've got this project - a very small Data Mart that we plan to build in less than a month.

I've talked through my design with the junior BI Developer and the Business Analyst who will be assisting me, but only briefly. How do I communicate the design to the team in a way that is efficient and effective? Something that has a bit of staying power, but not too much?

For efficiency and effectiveness I always try to "write the pictures first" - which, for an ETL package, means a flowchart with annotations.

I learned the concept of "writing the pictures first" from a college professor in Communications who taught me that when your medium includes a visual component you should assemble the visuals first. Tell as much of the story as possible with visuals and only after that avenue has been exhausted do you fill in words where the pictures have fallen short.

Thanks to Dr. Shook, when I document anything I always start with flow charts, tables, diagrams, charts and then move on to fill in the gaps with words. We all know it intuitively; specs with flowcharts and models always get us closer to communication than five paragraphs describing sequence and dependencies.

"Writing the pictures first" is especially sage advice in our globalized industry where our teams are assembled with people from diverse backgrounds.

And what about that "staying power but not too much"? What do I mean by that? It's a concept Scott Ambler wrote about in his book "Agile Modeling" almost a decade ago. Ambler notes that if you create an artifact and present it to your client, someone, somewhere it going to think that means you're going to always keep it up to date.

The effect of this unfortunate truth is that I, at least, have learned to avoid documenting things unless my arm is twisted up behind my back until I utter "Avuncular" or in this case "Okay I'll document it." The crazy thing is that I love documentation, I love writing it. I just don't
like maintaining it once it's outlived it's purpose. If the documentation isn't driving the development forward, I find it really frustrating to use valuable project time documenting history.

I find myself heading for the white board more often than not these days. I've figured out that I can't be asked why I didn't keep a document up-to-date if no one can prove it ever existed.

Funny thing is, the white board drawing often becomes the center of the project's universe. Everyone refers to it. Over and over. For weeks on end. Conversations shift from one cube to another because someone reached out mid-sentence to point to an arrow running from here to there and found "our drawing" wasn't within reach.

I want to have that drawing - that visual worth a thousand words- but I don't want to have to maintain it unless there's a really great reason to do so. I want the best of both worlds. And I think I've figured out how I can have it all.

I do my design in SSIS.

For one thing, I already have Visual Studio on my machine. The client made sure of that. I don't want to have to wait to get Visio approved and installed. My ETL design is going to be implemented in SSIS anyway, so why not draw it there in the first place.

Why not stub the whole thing out? I can write descriptive annotations out to the side to "fill in any gaps." The annotations will describe what I think I am going to do and the order I think I am going to do it. I can also pull in tasks - whatever type I think I might use for each annotated step.



When I have a rough design laid out I can print it to PDF or throw it up on projection screen and we can do a working design session - my whole team - by editing the skeleton of a package flow. As my team and I discuss the pros and cons and make better decisions about the best design I can edit the annotations right then and there.

When the session is over I can output the PDF again, print it and post it somewhere.

SSIS is very visual - and in that respect meets my criterion of "writing the pictures first" very well.

But the real beauty of an SSIS design flowchart is that it doesn't have to be maintained. Well, it sort of can't be maintained and can't keep from being maintained as the same time.

The design can't be maintained because it becomes the code. So as a design it ceases to exist. Then again, it becomes the code, the developed work, and in that sense it is always up-to-date as the documentation of the finaly implementation. Could it get any better than that?

When the design session is over I could potentially even hand off the SSIS package to the junior developer and they would have a sort of design scaffolding system within which to work. But even if I don't transfer the work, even if I fill in the details myself, the project is better because we have the common reference point, the visual that we communicate around without creating a documentation burden that will drag our project under.

In the end, all you have left is the real working code, and if you kept the annotations precise you have self-documenting code.

Thursday, February 4, 2010

Falling in Love with Degenerate Dimensions

Since February is the month of love, and my love for my husband is not so likely to have me waxing rhapsodic so many years into our courtship, I thought I'd talk about my burgeoning love of Degenerate Dimensions.

I've been flirting with the idea for a while now. The fact that I can use Microsoft's Data Source View to make the fact table look like itself, a fact table, but also have it contort itself into numerous additional dimension "views" using the Named Query option. All those views, one place, SSAS, to implement them.

What if I were to really throw caution to the wind? What if I implemented a cube with no dimension tables at all. None. With every dimension a degenerate, I only have one table to load. Sure, I have to put in a lot of varchar values to get things looking nice, but is that really as bad as it used to be? And will it totally take care of slowly-changing dimension issues? In a really elegant way?

I've got a client who has just 56 customers. The client is tracking things about these customers over a ten year span.

"Egads, 560 records!" you say, "You're going to put everything into a single fact table and make all the dimensions degenerate in a table that has 560 records and grows by less than a hundred records every year?"

I know. It's crazy talk. But falling in love is all about crazy.

Friday, January 29, 2010

Publishing Excel Spreadsheets on SSRS - Security Issue

Publishing a cube connected Excel Spreadsheet is a great way to distribute cube access to users. If you delivery mechanism is SSRS, you might notice that your permissions seem wonky.

We recently had this issue and I wanted to share the resolution:

Excel Spreadsheet links through SSRS are "Resources" not "Reports." Check your SSRS Security Roles to make sure that the users you intend to expose these spreadsheets to have the "View Resources" task checked (along with "View Reports").

More explicitly - for newer admins.

1) Navigate to the web interface for your SSRS server
2) Click "Site Settings" in upper right corner
3) Under the Security heading, click "Configure item-level role definitions"
4) Select "Browser"
4) Check "View Resources" (set value to 'True' by checking the box)
5) Click Ok to save and exit.

If you use SQL Server Mgmt Studio to manage SSRS:
1) Connect to your server using the Reporting Services connection type
2) Open the Security directory
3) Open the Roles directory
2) Right-click on your genearal user Role - usually "Browser" - and select "Properties"
3) Check the permission called "View Resources"
4) Save.

Thursday, January 14, 2010

Headstart on a Geography Dimension

Use this table to get started with a Geography Dimension. The next step for me will be to add zip codes or a County/Town/Neighborhood breakdown. Different clients will have different needs. You could store this table separate from a further breakdown and then either snowflake them in the Cube's Data Source View or use a named query in the Data Source view to combine them and star them.

ID

Name

ParentID

1

US

1

2

Northeast Region

1

3

Midwest Region

1

4

South Region

1

5

West Region

1

6

New England Div

2

7

Mid-Atlantic Div

2

8

East North Central Div

3

9

West North Central Div

3

10

South Atlantic Div

4

11

East South Central Div

4

12

West South Central Div

4

13

Mountain Div

5

14

Pacific Div

5

15

Maine

6

16

New Hampshire

6

17

Vermont

6

18

Massachusetts

6

19

Rhode Island

6

20

Connecticut

6

21

New York

7

22

New Jersey

7

23

Pennsylvania

7

24

Wisconsin

8

25

Michigan

8

26

Illinois

8

27

Indiana

8

28

Ohio

8

29

Missouri

9

30

North Dakota

9

31

South Dakota

9

32

Nebraska

9

33

Kansas

9

34

Minnesota

9

35

Iowa

9

36

Delaware

10

37

Maryland

10

38

District of Columbia

10

39

Virginia

10

40

West Virginia

10

41

North Carolina

10

42

South Carolina

10

43

Georgia

10

44

Florida

10

45

Kentucky

11

46

Tennessee

11

47

Mississippi

11

48

Alabama

11

49

Oklahoma

12

50

Texas

12

51

Arkansas

12

52

Louisiana

12

53

Idaho

13

54

Montana

13

55

Wyoming

13

56

Nevada

13

57

Utah

13

58

Colorado

13

59

Arizona

13

60

New Mexico

13

61

Alaska

14

62

Washington

14

63

Oregon

14

64

California

14

65

Hawaii

14