Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234»»

Dynamically create and populate staging tables from CSV files Expand / Collapse
Author
Message
Posted Wednesday, January 11, 2012 1:21 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, January 30, 2012 6:49 AM
Points: 94, Visits: 359

Actually, performing loops and tests in other languages is much easier. T-SQL is not that great a language in regards to either performance or feature sets. T-SQL's main advantage is that it has a database system hooked up to it.

I don't think you should give up on loops and tests just because T-SQL is not that great a programming environment, unless you're really just not that interested in programming in general.

/opinion


No TSQL is not the best language for performing loops. But there are few scenarios in etl, where loops are the best algorithm to process data. The transformations after staging fore me are typical exercises of set-based processing.
Post #1233769
Posted Wednesday, January 11, 2012 1:28 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 4:36 AM
Points: 242, Visits: 152
Jeff Moden (1/10/2012)
Stan,

Nice step-by-step article with some timely graphics to show how to do things. Although it wasn't specifically named as such, I believe that folks will come to realize that this is a very good "spackle" article that demonstrates the beginnings of a technique. Like any "spackle" article, it's not meant to be a complete solution but it'll sure get some thought juices going for people who have ever had to import "unknown number of columns" files like I've had to do in the past. You could have saved yourself a bit of commentary by identifying that the popups where there only for verification during development and, perhaps, more clearly identifying not only when this technique might be used along with suggested "next steps", but it's a good article. Thanks for taking the time to write it and share it.


Sorry Jeff - couldn't help laughing at this post. Not sure if you are aware of the slang "spackle": urban dictionary



Poor Stan
Post #1233772
Posted Thursday, January 12, 2012 7:21 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 5, 2014 2:53 PM
Points: 21, Visits: 83
This is good to generate an initial cut of the SQL code that I will then use at the start of my SSIS package to create the staging tables if not present, Of course for that I do not need the data loading part. I would use a dataflow task to do the actual loading.
Saves me some typing and hence typos.
Post #1234798
Posted Thursday, January 12, 2012 8:57 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, August 28, 2014 5:37 PM
Points: 536, Visits: 757
Thank you for the article. For .NET-challenged SQL developers like myself this provides a great starting point to go on and adapt this approach for our specific needs. Also thank you to everybody who contributed subsequent enhancements. You are a great bunch!


Post #1234932
Posted Thursday, January 12, 2012 9:21 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 9:58 AM
Points: 36,995, Visits: 31,517
surreydude. (1/11/2012)
Jeff Moden (1/10/2012)
Stan,

Nice step-by-step article with some timely graphics to show how to do things. Although it wasn't specifically named as such, I believe that folks will come to realize that this is a very good "spackle" article that demonstrates the beginnings of a technique. Like any "spackle" article, it's not meant to be a complete solution but it'll sure get some thought juices going for people who have ever had to import "unknown number of columns" files like I've had to do in the past. You could have saved yourself a bit of commentary by identifying that the popups where there only for verification during development and, perhaps, more clearly identifying not only when this technique might be used along with suggested "next steps", but it's a good article. Thanks for taking the time to write it and share it.


Sorry Jeff - couldn't help laughing at this post. Not sure if you are aware of the slang "spackle": urban dictionary



Poor Stan


Now THAT's funny. But, no... not the type of spackle I was referring to.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1234978
Posted Thursday, January 12, 2012 9:25 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 9:58 AM
Points: 36,995, Visits: 31,517
patrickmcginnis59 (1/10/2012)
Jeff Moden (1/10/2012)
Of course, you could also pre-process tables before they come anywhere near SQL Server but I've found that writing such code is a bit of a fright because you might not have set based, declarative tools such as are available in SQL Server to keep from having to write read/write routines with lots of loops and decisions on your own.


Actually, performing loops and tests in other languages is much easier. T-SQL is not that great a language in regards to either performance or feature sets. T-SQL's main advantage is that it has a database system hooked up to it.

I don't think you should give up on loops and tests just because T-SQL is not that great a programming environment, unless you're really just not that interested in programming in general.

/opinion


I'll have to resort to the "It Depends" aspect. If you want to check all data in a "field", it's a whole lot easier to do a test for it in a column in T-SQL than it is to write code to cycle through every row of that "field". Because T-SQL will use the very low-level "Pseudo Cursors" behind the scenes, it'll do it all at the same or almost the same speeds as writing an external validation script.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1234985
Posted Thursday, January 12, 2012 11:38 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, March 5, 2014 10:14 AM
Points: 477, Visits: 727
Although I don't particularly care for SSIS nor the fact that the technique in this article had to use a script to do the job (I did my thing 100% in T-SQL with no problems), the article is a reasonable introduction as to how you might begin to approach such a thing in SSIS.


Jeff,

I for one would be interested in getting eyes on the T-SQL solution you mention!

SJT



Post #1235154
Posted Saturday, June 23, 2012 10:54 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, September 21, 2012 2:54 AM
Points: 1, Visits: 16
Can Please any1 tell me what if we really want to know the data types of the columns and create the table accordingly. For small no. of files we can even do this thing 1 by 1 . But if the files are in 1000 s then what should be the proper solution to built the staging database. Please suggest some 1 its urgently required.
Can I use any .dll file and modify it accodingly to get the requirement done.
Post #1320266
Posted Thursday, January 10, 2013 1:40 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 12:13 PM
Points: 69, Visits: 289
Hi All,

Can I use this with excel files ??
Post #1405632
Posted Thursday, January 10, 2013 2:44 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, August 11, 2014 8:51 AM
Points: 128, Visits: 911
Reading Excel files is not trivial. You can export them to CSV files out of Excel. CSV files will work fine.

You would have to convert them manually one-at-a-time, unless you purchase a third-party application like the one at this link:

http://www.softinterface.com/Convert-XLS/Features/Convert-XLSX-To-CSV.htm
Post #1405651
« Prev Topic | Next Topic »

Add to briefcase «««1234»»

Permissions Expand / Collapse