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 2000 Forums
 Import/Export (DTS) and Replication (2000)
 about how to create csv file with sql query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-11-29 : 08:13:12
manoj writes "Hi
I have one major query .. I have to get all record which is coming from sql-query into csv file I am writing to code for this ..




DECLARE @cmd VARCHAR(2048)
SET @cmd = 'OSQL -Smanoj -dAccessManager -E'
+ ' -Q" select m.Name as Nephrologistname , t.name State,'
+ ' p.State,l.UPIN,p.patient_id ,P.MedicalRecordNo,p.FirstName,'
+ ' p.MiddleName,p.LastName,p.Matiral_status,p.Address1,p.Address2,p.ZIPCode,'
+ ' p.Country,p.Telephone1,p.DOB,p.SSN,p.Nephrologist_Id from tblPatients p left outer JOIN tblMasters m'
+ ' on p.Nephrologist_Id=m.serialno and masterType=1'
+ ' left outer join tblMasters t on p.state=t.serialno and t.Mastertype=3 left outer join tblMastersAddtnl l on t.serialno=l.UPIN"'
+ ' -oG:\CLDUtest.csv'
EXEC master..xp_cmdshell @cmd, NO_OUTPUT


**************************************************


This is created one CLDtest.csv file but record is not coming as column by column as it looks very strange file ...


Please give me the soltion, how i will get csv file in arrange record as sql result comes...

Thanks


Manoj Kumar srivastava"

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-11-29 : 08:43:15
Rather than using osql, try to use BCP with QUERYOUT option.

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2006-11-29 : 18:58:41
http://msdn2.microsoft.com/en-us/library/ms162802.aspx


SqlSpec: a fast and comprehensive data dictionary generator for
SQL Server 2000/2005, Analysis Server 2005, Access 97/2000/XP/2003
http://www.elsasoft.org
Go to Top of Page
   

- Advertisement -