Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query help for Data pulling


Query help for Data pulling

Author
Message
DBA12345
DBA12345
Valued Member
Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)

Group: General Forum Members
Points: 56 Visits: 240
I need to pull the info from excel to the Database table through SSIS. I need logic for below scenario.

Excel Look like below:

Server Cost Values
SAB245 DRU 200
SAB246 DRU 2001
SAB247 TAPE 300
SAB248 TAPE 3001
SAB249 DISK 100
SAB250 DISK 1001


Output table should be:

Server DRU TAPE Disk
SAB245 200 Null Null
SAB246 2001 Null Null
SAB247 Null 300 Null
SAB248 Null 3001 Null
SAB249 Null Null 100
SAB250 Null Null 1001

Please let me know if you need more explanation.

thanks
Ray M
Ray M
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1491 Visits: 1076
You need to place a derived column transformation between your source and your Destination Containers.

Here is a tutorial on how to use the derived column transformation
http://sqlblog.com/blogs/andy_leonard/archive/2009/02/04/ssis-expression-language-and-the-derived-column-transformation.aspx
DBA12345
DBA12345
Valued Member
Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)

Group: General Forum Members
Points: 56 Visits: 240
What would be the logic int his scenario.
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24278 Visits: 37987
DBA12345 (4/3/2013)
I need to pull the info from excel to the Database table through SSIS. I need logic for below scenario.

Excel Look like below:

Server Cost Values
SAB245 DRU 200
SAB246 DRU 2001
SAB247 TAPE 300
SAB248 TAPE 3001
SAB249 DISK 100
SAB250 DISK 1001


Output table should be:

Server DRU TAPE Disk
SAB245 200 Null Null
SAB246 2001 Null Null
SAB247 Null 300 Null
SAB248 Null 3001 Null
SAB249 Null Null 100
SAB250 Null Null 1001

Please let me know if you need more explanation.

thanks


Are DRU, TAPE, and DISK the only values you have to worry about here?

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
DBA12345
DBA12345
Valued Member
Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)

Group: General Forum Members
Points: 56 Visits: 240
yes..I need to get those values in seperate columns with respective values
Ray M
Ray M
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1491 Visits: 1076
In the Derived column transformation you add 3 rows.
and the expression for DRU would be a very simple one.

Cost == "DRU" ? Values : NULL(DT_I4)

Of course repeat the process for the Disk and Tape by adding 2 more derived columns.

Edit: Added Image
Attachments
example.jpg (7 views, 228.00 KB)
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24278 Visits: 37987
Does this help you figure out how to query the data into a format you can use? Personally, I'd load the data as is from Excel into a staging table then pivot it from there using SQL.




declare @TestTable table(
ServerName varchar(10),
Cost varchar(4),
Value int);

insert into @TestTable
values
('SAB245','DRU',200),
('SAB246','DRU',2001),
('SAB247','TAPE',300),
('SAB248','TAPE',3001),
('SAB249','DISK',100),
('SAB250','DISK',1001);


select
ServerName,
DRU,
[TAPE],
[DISK]
from
(select
ServerName,
max(case Cost when 'DRU' then Value end) as DRU,
max(case Cost when 'TAPE' then Value end) as [TAPE],
max(case Cost when 'DISK' then Value end) as [DISK]
from
@TestTAble
group by
ServerName
)dt;




Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Ray M
Ray M
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1491 Visits: 1076
Lynn Pettis (4/3/2013)
Does this help you figure out how to query the data into a format you can use? Personally, I'd load the data as is from Excel into a staging table then pivot it from there using SQL.




declare @TestTable table(
ServerName varchar(10),
Cost varchar(4),
Value int);

insert into @TestTable
values
('SAB245','DRU',200),
('SAB246','DRU',2001),
('SAB247','TAPE',300),
('SAB248','TAPE',3001),
('SAB249','DISK',100),
('SAB250','DISK',1001);


select
ServerName,
DRU,
[TAPE],
[DISK]
from
(select
ServerName,
max(case Cost when 'DRU' then Value end) as DRU,
max(case Cost when 'TAPE' then Value end) as [TAPE],
max(case Cost when 'DISK' then Value end) as [DISK]
from
@TestTAble
group by
ServerName
)dt;




This would work if you were pulling from sql, however since pulling from excel it would be ineffective.
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24278 Visits: 37987
Ray M (4/3/2013)
Lynn Pettis (4/3/2013)
Does this help you figure out how to query the data into a format you can use? Personally, I'd load the data as is from Excel into a staging table then pivot it from there using SQL.




declare @TestTable table(
ServerName varchar(10),
Cost varchar(4),
Value int);

insert into @TestTable
values
('SAB245','DRU',200),
('SAB246','DRU',2001),
('SAB247','TAPE',300),
('SAB248','TAPE',3001),
('SAB249','DISK',100),
('SAB250','DISK',1001);


select
ServerName,
DRU,
[TAPE],
[DISK]
from
(select
ServerName,
max(case Cost when 'DRU' then Value end) as DRU,
max(case Cost when 'TAPE' then Value end) as [TAPE],
max(case Cost when 'DISK' then Value end) as [DISK]
from
@TestTAble
group by
ServerName
)dt;




This would work if you were pulling from sql, however since pulling from excel it would be ineffective.


Not if you load it into a staging table in SQL first then use SQL to complete the transform to the final table as I suggested.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Ray M
Ray M
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1491 Visits: 1076
Not if you load it into a staging table in SQL first then use SQL to complete the transform to the final table as I suggested.




Lynn Pettis

Sure it would but missed that part.
w00t
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search