Business Intelligence Blogs

View blogs by industry experts on topics such as SSAS, SSIS, SSRS, Power BI, Performance Tuning, Azure, Big Data and much more! You can also sign up to post your own business intelligence blog.

«October 2015»

Data Warehouse from the Ground Up at SQL Saturday Orlando, FL on Oct. 10th

SQL Saturday #442SQL Saturday #442 is upon us and yours truly will be presenting in Orlando, Florida on October 10th alongside Mitchell Pearson (b|t). The session is scheduled at 10:35 AM and will last until 11:35 AM. I’m very excited to be presenting at SQL Saturday Orlando this year as it’ll be my first presenting this session in person and my first time speaking at SQL Saturday Orlando! If you haven’t registered yet for this event, you need to do that. This event will be top notch!

My session is called Designing a Data Warehouse from the Ground Up. What if you could approach any business process in your organization and quickly design an effective and optimal dimensional model using a standardized step-by-step method? In this session I’ll discuss the steps required to design a unified dimensional model that is optimized for reporting and follows widely accepted best practices. We’ll also discuss how the design of our dimensional model affects a SQL Server Analysis Services solution and how the choices we make during the data warehouse design phase can make or break our SSAS cubes. You may remember that I did this session a while back for Pragmatic Works via webinar. I’ll be doing the same session at SQL Saturday Orlando but on-prem! ;)

So get signed up for this event now! It’s only 11 days away!

Read more

Create Date Dimension with Fiscal and Time

Here are three scripts that create and Date and Time Dimension and can add the fiscal columns too. First run the Dim Date script first to create the DimDate table. Make sure you change the start date and end date on the script to your preference. Then run the add Fiscal Dates scripts to add the fiscal columns. Make sure you alter the Fiscal script to set the date offset amount. The comments in the script will help you with this.

This zip file contains three SQL scripts.

Create Dim Date

Create Dim Time

Add Fiscal Dates

These will create a Date Dimension table and allow you to run the add fiscal script to add the fiscal columns if you desire. The Create Dim Time will create a time dimension with every second of the day for those that need actual time analysis of your data.

Make sure you set the start date and end date in the create dim date script. Set the dateoffset in the fiscal script.

Download the script here:


Read more

Exporting Data Using BCP

  • 20 August 2012
  • Author: BradSchacht
  • Number of views: 581

BCP, or bulk copy program, has been around in SQL Server for a long time. It is a great way to export large quantities of data very quickly from SQL Server. It can be used to export entire tables or even a custom query. In this post we will focus on doing some simple commands to export data. This is by no means a complete and comprehensive look at BCP. My only intention with this post is to get you started and maybe provide a quick syntax reference for doing BCP in the future.

The obvious choice to move data out to a flat file may be SSIS. BCP could not be any more of a polar opposite in actually implementing the data export in that SSIS is a completely developed in a GUI and BCP is completely developed at the command prompt.

To get started open up a new command prompt window on your computer. You may want to go ahead and run it as administrator in case you want to put the file someplace like the C:\ drive and have UAC turned on. If you simply type BCP at the command prompt a series of available commands will be displayed. We will only touch on a couple of those:

You can see in the screenshot the basic syntax for BCP is [What to Export] [in or out] [file]

BCP AdventureWorks.Production.Product out C:\Production_Product.txt

The second parameter can actually have one of four values:

  • in - Copy data into a table or view from a file
  • out - Copy data from a table or view to a file
  • queryout - Copy data from a query to a file (query must be provided enclosed in quotes, not a table or view name)
  • format - Creates a format file based on the table, view or query specified

There are several other parameters you will want to be sure to include keeping in mind each is case sensitive:

  • -S ServerName\InstanceName
  • Authentication
    • -U Username and -P Password
    • -T Windows Authentication
  • Data Types
    • -c Character data types
    • -n Uses the native data types from the source system
    • Do not specify anything and you will be prompted to provide a data type for each column

Now for a couple of samples:

For each of these I am going to be using windows authentication to connect to a named instance on my local machine. This can connect to other servers however and the files can also be sent to a network share as well.

Table Export: BCP AdventureWorks.Production.Product OUT C:\ProductionProduct.txt -S localhost\SQL2008R2 -T -c

Notice that 504 rows were exported in well under a second at 504,000 rows per second.

Query Export: BCP "SELECT * FROM AdventureWorks.Production.ProductModel" QUERYOUT C:\ProductionProductModel.txt -S localhost\SQL2008R2 -T -c

The results in this case are similar: 128 rows exported, still under a second and 1,376 rows per second.

Notice what happens when providing a query and specifying OUT instead of QUERYOUT:

Unfortunately the error is not all that great, we are just told that an error occurred while processing the command line.

Just to show what happens when exporting a table with more than just a couple of records here is a screenshot of the export from ContosoRetailDW.dbo.FactOnlineSales

Hope this sheds some light on exporting data with BCP. Be on the lookout for some information coming on importing data with BCP as well as a performance comparison between BCP and SSIS direct to a flat file.

Want to explore the BCP options in more detail? Head over to the MSDN page:

Categories: Big Data, SQL Server
Rate this article:
No rating


Other posts by BradSchacht

Please login or register to post comments.