query how to load data from database to text file
have table has lot of data in it.
it has many columns...like fn,ln,mn,dob,gender,ssn,mrn,datasource(int),uno(primary key),address1,address2,city,state,zip code....
same person appear more 1 time different datasource number
uno , datasource key table.
example of data
uno datasource
1 2
1 23
1 33
2 3
2 5
2 6
when use query
select max(datasource),uno table group uno
output
uno datasource
1 33
2 6
since have other columns fn,ln,dob etc etc etc as mentioned above
i want output should have columns
required output
uno datasource fn ln dob gender etc etc
1 33 test1 test1 01/01/01 m
2 6 test2 tet2 01/10/2000 f
i want output text file.
please let me know
it has many columns...like fn,ln,mn,dob,gender,ssn,mrn,datasource(int),uno(primary key),address1,address2,city,state,zip code....
same person appear more 1 time different datasource number
uno , datasource key table.
example of data
uno datasource
1 2
1 23
1 33
2 3
2 5
2 6
when use query
select max(datasource),uno table group uno
output
uno datasource
1 33
2 6
since have other columns fn,ln,dob etc etc etc as mentioned above
i want output should have columns
required output
uno datasource fn ln dob gender etc etc
1 33 test1 test1 01/01/01 m
2 6 test2 tet2 01/10/2000 f
i want output text file.
please let me know
may not efficient way, using correlated sub query work. create datasource , use subquery go destination of flat file. in order replicate data best possible used adventureworks humanresources.employee , person.contact:
hope helps
david dye
use [tempdb] |
create table #test( |
uno int, |
fn varchar(75), |
ln varchar(75), |
datasource int |
) |
insert #test |
select top 100 c.contactid, |
firstname, |
lastname, |
managerid |
from adventureworks.person.contact c join adventureworks.humanresources.[employee] e |
on c.[contactid] = e.[contactid]; |
go |
insert #test |
select top 100 c.contactid, |
firstname, |
lastname, |
employeeid |
from adventureworks.person.contact c join adventureworks.humanresources.[employee] e |
on c.[contactid] = e.[contactid]; |
go |
select * |
from #test |
order by uno; |
go |
results |
1001 terri duffy 109 |
1001 terri duffy 12 |
1002 roberto tamburello 3 |
1002 roberto tamburello 12 |
1005 gail erickson 3 |
1005 gail erickson 9 |
select distinct uno, |
fn, |
ln, |
(select max(tt.datasource) |
from #test tt |
where tt.uno = t.uno) as datasource |
from #test t |
order by uno; |
go |
results |
1001 terri duffy 109 |
1002 roberto tamburello 12 |
1005 gail erickson 9 |
drop table #test; |
go |
hope helps
david dye
SQL Server > SQL Server Integration Services
Comments
Post a Comment