Pet CPR

February 27th, 2012

Found this on Facebook: Ban Stupid People Not Pitbulls

SSIS: Import Excel File Into SQL Database

February 20th, 2012

I need to import data from a single Excel (.xls) file into a SQL database table. A simple way to import the data is by using SSIS (SQL Server Integration Services).

Here is my file (Company2.xls):

My Excel file looks like:

*I created this tutorial while also making another one, hence the Excel Loop SSIS everywhere. You can check out that tutorial here: Excel Loop Into SQL

I’m using Microsoft Visual Studio 2008

1. Open up Visual Studio.

2. Under Project Types select Business Intelligence Projects.

3. Under Templates select Integration Services Project.

4. Select a Name & Location at the bottom. You can also add a Solution Name. (I didn’t).

5. Click OK.

*I like to be a little lazy and just use the Wizard. So for this tutorial, that’s what I am showing.

6. Inside of Solution Explorer, right-click on SSIS Packages and select SSIS Import and Export Wizard from the pop-out menu.

7. The SQL Server Import and Export Wizard window will pop up next.

8. Choose a Data Source:
   a. Data Source: Microsoft Excel
   b. Excel file path: select your .xls file. (Mine is Company2.xls)
   c. Be sure to check First row has column names, if your file has the column names in the first row!

9. Click Next.

10. Choose a Destination:
   a. Destination: SQL Server Native Client 10.0
   b. Server name: select your server name (I’m using localhost)
   c. Authentication: You can either use Windows Authentication or SQL Authentication. If you use SQL Authentication, you must enter your User name and Password. (I’m using Windows Authentication)
   d. Database: select your database name here. (I’m using one called Amys)

11. Click Next.

12. Specify Table Copy or Query window is next. Select Copy data from one or more tables or views:

13. Click Next.

14. Select Source Tables and Views comes up next.
   a. Select your Source (the Excel sheet name). Mine is simply ‘Sheet1$’ (the default sheet name from Excel)
   b. Select your Destination (the SQL table name you want the excel data entered into). In my case, I haven’t made a table yet, so I’m going to type in: [dbo].[Tut-SSISExcelLoop]

   c. Click on Edit Mappings. Here you can match up your Excel & SQL column names. Since I don’t have a table made already, I have Create destination table selected and the the wizard automatically matched up my columns for me. If I wanted, I can change the SQL column types under Mappings: then Type. If you already have a table recreated you can select Delete rows in destination table or Append rows to the destination table. Depends if you just need to delete everything and add new or if you want to add additional information to the table.

15. Click OK.

16. This returns you to the Select Source Tables and Views window. You can click Preview to preview how your data will look. Click Next.

17. Next the Complete the Wizard window comes up. Just click Finish.

18. The execution was successful window comes up next. Here it will show you if you have any Errors or Warnings. If there are red x’s, you have a problem. Since the wizard is creating a new destination table for me, and it picked out my column types, I have no Errors or Warnings, just green Success checks. Click Close.

19. Once you click Close you will be brought back to Control Flow.

20. Right-click Preparation SQL Task 1 and select Edit, the Execute SQL Task Editor window will pop up:

*This only shows up if you chose Create destination table in step 14. c.

   a. This SQL Task is creating a new table using the Connection DestinationConnectionOLEDB that we made in step 10.

21. Right-click on Data Flow Task 1 and select Edit. This will take you to the Data Flow tab. This shows your Source inserting into your Destination

22. Right-click on your Source (Mine is called: Source – Sheet1$) and click Edit.
   a. Connection Manager shows your OLE DB connection name, the Data access mode and the Name of the Excel sheet.

   b. Columns shows the column names from you Excel sheet and the Output Column names.

   c. Error Output shows what to do on errors. You can change the Error type and Truncation.

23. Click OK to save changes or Cancel to exit.

24. Click Run to Execute your package.

25. Both Preparation SQL Task 1 and Data Flow Task 1 should turn green, indicating Success. (If yours turns red, check the Output tab at the bottom for errors).

26. Now open up Microsoft SQL Server Management Studio, Select your database and then select all files in your table. The excel file data you just imported should show up:

SSIS: How To Strip Double Quotes ” From .csv File on Import

February 20th, 2012

This is a quick tutorial to show you how to strip/remove the double quotes ” from columns in a .csv file when importing with SSIS (SQL Server Integration Services).

I like to use the wizard, since it’s quick and easy.

1. Right-click SSIS Packages in your Solution Explorer.
2. Select SSIS Import and Export Wizard.

3. When the SQL Server Import and Export Wizard comes up change the Data Source to Flat File Source.
4. Select your file name by hitting Browse.
5. Under Format you need to change the Text qualifier from <none>  to (double quotes):

(Note: I have checked Column names in the first data row because my .csv file has the column names. Do not check this if your file does not have the column names)

6. Now if you click on Preview you will see your columns without the (double quotes):

7. Now you can hit Next on the wizard and choose your Destination Connection and follow through how you normally would.

It’s really just that simple!

SSIS ManagedDTS .dll Assembly

February 13th, 2012

1. Run C:\Windows\assembly\gac_msil in the Run box from Start

2. Find the dll in folder Microsoft.SqlServer.ManagedDTS

3. Copy the dll

To add assembly .dll reference to code

SSIS Excel Loop Into SQL

February 8th, 2012

If you don’t know how to import an Excel file into a SQL database, check out my tutorial here: SSIS: Import Excel File Into SQL Database

I have a folder with multiple Excel files (.xls) that I need SSIS (SQL Server Integration Services) to loop through and insert into a SQL table.

Here are my files:

Each file is setup like this:

Note: It doesn’t matter what your file names are, as long as they are .xls extension. Make sure all the headers (row 1) are identical through out each file.

I’m using Microsoft Visual Studio 2008

1. Use the SQL Server Import and Export Wizard to import excel into sql. (pick any one of the .xls files in the folder you want.)

2. Drag a Foreach Loop Container to the workspace.

3. Drag the Data Flow Task 1 we just created into the Foreach Loop Container.

4. Right-click on the Foreach Loop Container and select Edit .

5. This brings up the Foreach Loop Editor

6. Go to the Collection tab:
   a.Enumerator: Click on Foreach File Enumerator
   b.Folder: where the files are contained
   c.Files: *.xls
   d.Retrieve file name: Fully qualified

7. Select the Variable Mappings tab:
   a.Click under Variable, on drop down choose New Variable. Leave everything but change name to: FileWeJustFound. (Note Package2 is what my package name is)


   b.Click OK.
   c.Index should be set to 0 (default)

   b.Click OK.

REST OF UPDATE COMING SOON:

8.Right-click the Foreach Loop Container and select properies
   a. Find DelayValidation and set to True

9. Right-click on the SourceConnectionFile which is located inside of Connection Managers
   a. Locate Expressions and click the ellipsis (…) next to it.

   b. Property: Connection String
   c. Expression: “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + @[User::FileWeJustFound] + “;Extended Properties=\”Excel 8.0;HDR=Yes\”" You can also click the ellipsis (…) next to it to open up the Expression Builder: (if copying & pasting from here, replace the ” with real ones)

   d. Click OK.

10. Now you should be able to run the package:

11. The package will loop through all your .xls files and import them into SQL. You should get a screen that looks like the one below. If your package is red instead of green, be sure to check the Output to see what errors may have happened.

12. Now open up Microsoft SQL Server Management Studio, Select your database and then select all files in your table. The excel file data you just imported should show up:

I learned from: http://www.sqlis.com/sqlis/post/Looping-over-files-with-the-Foreach-Loop.aspx

SQL – Shorten Date Remove Time

January 31st, 2012

CONVERT(VARCHAR(10), [myDateColumnName], 101) AS [myDateColumnName]

Make datetime shorter, show only date not time

before:
2012-01-31 00:00:00.000

after:
01/31/2012

Ellie Goulding – Starry Eyed

August 3rd, 2011

So Steve @ work introduced me to Ellie Goulding. I gotta say, she’s pretty awesome! This song will get stuck in your head – BEWARE!! Her whole album, Lights, is really good! I highly recommend it :)

 

 

July 2011 Birchbox

July 16th, 2011

I got my very first Birchbox today! I was really excited to open it up and see what was inside. I have to say, first off, their packaging was really pretty and wrapped up like a present! Love it! Birchbox teamed up with Cynthia Rowley, an American fashion designer, for this box. So far I haven’t tried anything but the nail polish. I like the nude, pinkish color of it, very different from what I usually get. Here are the pictures & description:

1. AHAVA – Mineral Hand Cream (3.4oz $20)
Loaded with Dead Sea minerals, this fast-absorbing cream heals dry hands without a smidge of residue.

2. philosophy® – purity made simple one-step facial cleanser™ (8oz $20/ 16oz $32)
This perennial award-winner is pH-balanced to gently clear away dirt, oil, and makeup without drying out skin.

3. Redken – shine flash™ 02 (4.4oz $17)
A must for all Cynthia’s runway shows, this weightless spray gives hair a brilliant finish.

4. Zoya – Touch Collection Nail Polish in Shay (0.5 flz oz $8)
Neutral gets a sexy makeover in this creamy, slightly metallic nude. The perfect accessory to summer’s bright fashions.

EXTRA KIND – Almond & Apricot
Snack right with this wholesome bar – no preservatives or hard-to-pronounce ingredients.

Frank’s Red Hot Chicken Dip Recipe

July 9th, 2011

I found this recipe in the sunday newspaper. Every time I make it, it’s a huge hit and people request the recipe :)

5/5 stars

Ingredients:
1 pkg (8 oz.) cream cheese, softened
1/2 cup any flavor Frank’s RedHot sauce
1/2 cup blue cheese salad dressing
1/2 cup crumbled blue cheese
2 cans (12.5 oz each) Swanson Premium Chunk Chicken Breast, drained
Assorted fresh vegetables and/or crackers, and/or tortilla chips for dipping.

Directions:
1. Stir cream cheese in 9″ deep dish pie plate with fork until smooth. Stir in dressing, hot sauce and blue cheese. Stir in chicken.

2. Bake at 350°F for 20 minutes until hot and bubbling. Stir. Serve with veggies, crackers and/or tortilla chips

CSS Rounded Corners

July 8th, 2011

Check out this awesome website of CSS code for rounded corners: CSS Border Radius Generator

It seems to work great in Chrome & Firefox… not so much IE, but then again are you surprised?