Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 T-SQL Code Help

Author  Topic 

tooba
Posting Yak Master

224 Posts

Posted - 2014-10-25 : 02:02:03
Hi All,

Here is my sample source file

Advert,Network,Program
Acorn,NULL,NULL
NULL,AC,NULL
NULL,NULL,Adult

and I want

Advert,Network,Program
Acorn,AC,Adult

Please help/guide, its urgent.

Thank You in Advance.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-10-25 : 02:34:32
your table only have 3 records ?

select max(advert), max(network), max(program) from sample_source_file



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tooba
Posting Yak Master

224 Posts

Posted - 2014-10-25 : 02:43:31
No, this is just a sample data here is in detail sample file

Advert,Network,Program
Acorn,NULL,NULL
NULL,AC,NULL
NULL,NULL,Adult
Jame,Null,Null
Null,IC,Null
Null,Null,Young
Null,Null,Adult
Fix,Null,Null
Null,GM,Null
Null,Null,Kid

The first three rows are set of Advert = Acorn
Second four rows are set of Advert = Jame
and last three rows are set of Advert = Fix

Thank You.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-10-25 : 02:47:20
how do you identify which rows belong to the same set ? Is there another column in the table that is able to do that ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tooba
Posting Yak Master

224 Posts

Posted - 2014-10-25 : 02:52:44
No there is no other column. How do I identify, to be honest not sure. As per excel file that we are receiving its like that.
In first column (Advert) is null its mean its with the same set and if its not null its mean new sets start.
Go to Top of Page

tooba
Posting Yak Master

224 Posts

Posted - 2014-10-25 : 02:54:24
Actually what I am doing, receiving file from Client with this crazy format. From this file I just need few columns and create a , separated file.
Go to Top of Page

tooba
Posting Yak Master

224 Posts

Posted - 2014-10-25 : 02:56:32
and I am using SSIS for this project/task.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-10-25 : 02:57:40
for your information, records in table is not stored in any particular sequence or ordering.

You define how the ordering of records retrieve by using ORDER BY clause.

How do you import the data from excel into the table ?




KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tooba
Posting Yak Master

224 Posts

Posted - 2014-10-25 : 03:04:35
The Source File/Field (Advert) are always ace order. I mean that data is in excel file is always ACE order.

Is there any way we can use update statement to update with previous value, here is below example

Fname
Smith
James
Null

After update
Fname
Smith
James
James
?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-10-25 : 03:14:25
quote:
Is there any way we can use update statement to update with previous value

provided that you have a column to identify the ordering or sequence of records.

Possible to fix the data in excel before import into SQL Server ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tooba
Posting Yak Master

224 Posts

Posted - 2014-10-25 : 03:20:19
My source file/sample file like this

Advert,Network,Program
Acorn,NULL,NULL
NULL,AC,NULL
NULL,NULL,Adult
Fix,Null,Null
Null,IC,Null
Null,Null,Young
Null,Null,Adult
Jim,Null,Null
Null,GM,Null
Null,Null,Kid

in Excel File. I want to do something in SSIS or I was thinking just straight dump the data in to SQL Table with create Row Number in SSIS and then use sql table on sql table.
Go to Top of Page

tooba
Posting Yak Master

224 Posts

Posted - 2014-10-25 : 03:23:19
We are receiving this file everyday from client, Cant fix this manually everyday and Client are not going to send different format file. I have to deal with this crazy format....
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-10-25 : 03:34:05
you can try adding an identity column in the table, but I am not sure how SSIS imports from excel to table, probably there is a way to ensure the insertion is as per the sequence in excel ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -