SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 
        
Home       Members    Calendar    Who's On


12»»

adding column to the table Expand / Collapse
Author
Message
Posted Friday, November 06, 2009 1:11 PM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Yesterday @ 11:56 AM
Points: 121, Visits: 290
Hi,
I have .txt that i am trying to load into sql table using SSIS2005
and the destination is SQL 2005.
The text file will have a header and data.
The format of the .txt will be as follows
CodeValues for the period ending 11/04/09
CodeValue
AZX123X
AZS143X
ADSE23V

This has to be loaded into a table with the date from the
header as a column
For example,
table format should be like this

CodeValue EndDate
AZX123X 11/04/09
AZS143X 11/04/09
ADSE23V 11/04/09

I am able to trim the hearder but not able to add this date column
from the header to the rows,
any ideas of to do this?


Thanks,
Post #815162
Posted Friday, November 06, 2009 1:31 PM


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: Today @ 10:18 PM
Points: 563, Visits: 476
I may give it a try if you can give the text file as attachment here, truncate the large portion of the data, so it can be a sample.

Regards,
Bru Medishetty
www.LearnSQLWithBru.com
Post #815173
Posted Friday, November 06, 2009 1:36 PM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Yesterday @ 11:56 AM
Points: 121, Visits: 290
Hi,
Please find the attachment.

Thanks,


  Post Attachments 
New Text Document.txt (20 views, 377 bytes)
Post #815174
Posted Friday, November 06, 2009 1:38 PM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Yesterday @ 11:56 AM
Points: 121, Visits: 290
and this file have to be loaded to a table
as
Policy No Date
as the columns, and date values have to be populated from the header in the text file.

Thanks,
Post #815176
Posted Friday, November 06, 2009 1:46 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 7:53 PM
Points: 1,852, Visits: 660
Try loading the date from the header into a variable and then add a data transformation task for a derived colum. The value in the derived column that you will add will be your variable that holds the date in the variable.



Jason
Why, so Serious?

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
How Many VLFs in the Tran Log - Kimberly Tripp
Post #815181
Posted Friday, November 06, 2009 1:49 PM


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: Today @ 10:18 PM
Points: 563, Visits: 476
Follow Jason's Suggestion that should work.

Regards,
Bru Medishetty
www.LearnSQLWithBru.com
Post #815185
Posted Friday, November 06, 2009 1:50 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 2:21 AM
Points: 1,666, Visits: 1,581
CirquedeSQLeil (11/6/2009)
Try loading the date from the header into a variable ...


That's not as easy as you've made it sound - unless you know a method I haven't thought about. Were you thinking about using a script to read the first few lines and then using 'ignore first x lines' when reading the rest of the file in a standard DF?



Post #815186
Posted Friday, November 06, 2009 1:58 PM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Yesterday @ 11:56 AM
Points: 121, Visits: 290
CirquedeSQLeil (11/6/2009)
Try loading the date from the header into a variable .


Can you explain a little on how to do this? Please!

Thanks,
Post #815189
Posted Saturday, November 07, 2009 9:39 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:15 PM
Points: 18,300, Visits: 12,321
Let me ask this... does it have to be done in SSIS? The reason I ask is because this is a trivial task in T-SQL.

--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."

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #815515
Posted Saturday, November 07, 2009 10:14 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:15 PM
Points: 18,300, Visits: 12,321
Jeff Moden (11/7/2009)
Let me ask this... does it have to be done in SSIS? The reason I ask is because this is a trivial task in T-SQL.


Heh... see what I mean?
--===== Create a temp table to import the file to
CREATE TABLE #AllData (RawData VARCHAR(8000))

--===== Import the data into a single column using all defaults.
BULK INSERT #AllData
FROM 'C:\Temp\SomeFile.txt' --This is where I saved the example file

--===== Declare some obviously named local variables
DECLARE @PeriodEnding DATETIME

--===== Populate a variable with the Period Ending date from the file header
SELECT TOP 1 --Just to short circuit the table scan...
@PeriodEnding = SUBSTRING(RawData,PATINDEX('%[0-1][0-9]/[0-3][0-9]/[2][0-9][0-9][0-9]%',RawData),10)
FROM #AllData
WHERE RawData LIKE '%FOR PERIOD ENDING [0-1][0-9]/[0-3][0-9]/[2][0-9][0-9][0-9]%'

--===== Return a result set with the CodeValue numbers and the Period Ending date...
SELECT LTRIM(RTRIM(RawData)) AS CodeValue,
@PeriodEnding AS EndDate
FROM #AllData
WHERE SUBSTRING(RawData,2,1) > ''
AND RawData NOT LIKE ' POLICY NO%'

I suppose you could even turn it into a stored procedure with a bit of dynamic SQL so you could pass the file you want to load as a parameter and run the stored proc from SSIS... but, all things considered, why even bother with SSIS?


--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."

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #815519
« Prev Topic | Next Topic »

12»»

Permissions Expand / Collapse