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
 General SQL Server Forums
 New to SQL Server Programming
 UNLOAD TXT FILE

Author  Topic 

nguyenl
Posting Yak Master

128 Posts

Posted - 2008-03-20 : 16:40:55
Hi,

I was wondering what SQL code would allow me to extract my results into a .txt.

For example:

Select * from employees

(What should I write here to enable me to import it into a .txt file and save it on a network drive?)

Thanks

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2008-03-20 : 17:28:11
You can use DTS (SQL2K) to export to a file in several different formats. Right click on the table in EM and select export data. A wizard will popup. Follow it from there.

Terry
Go to Top of Page

nguyenl
Posting Yak Master

128 Posts

Posted - 2008-03-20 : 19:09:37
Is there anyway to write this manually? My script involves multiple tables and joins.

For example:

select distinct compass_compass_cd_cd, code_table.code_table_cd into #compass_cd
from cmpnt_address,code_table
where cmpnt_address.compass_compass_cd_cd = code_table.id
go

select distinct street_type_cd, code_table.code_table_cd into #street_cd
from cmpnt_address,code_table
where cmpnt_address.street_type_cd = code_table.id
go

SELECT address_id,
cmpnt_address.street_number,
cmpnt_address.number_compass_cd,
cmpnt_address.to_number,
cmpnt_address.to_number_compass_cd,
cmpnt_address.unit_number,
compass_cd.code_table_cd compass_cd,
cmpnt_address.street_name,
street_cd.code_table_cd street,
compass_cd.code_table_cd compass_cd,
address.city,
address.zip_postal_code,
cmpnt_address.unit_cd

FROM property,
cmpnt_address,
address,
compass_cd,
--outer compass_cd suffix,
street_cd

WHERE property.situs_address_id = cmpnt_address.address_id
AND cmpnt_address.street_type_cd = street_cd.street_type_cd
AND cmpnt_address.address_id = address.id
AND cmpnt_address.compass_compass_cd_cd = compass_cd.compass_compass_cd_cd
AND cmpnt_address.compass_compass_cd_cd = compass_cd.compass_compass_cd_cd
ORDER BY address_id


I would lIke to them export this into a .txt file.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-03-21 : 20:26:53
You can run sql statement with sqlcmd, that let you specify output file.
Go to Top of Page
   

- Advertisement -