Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting Query

Status
Not open for further replies.

straud13

Technical User
Nov 25, 2003
21
CA
I have written a query and tried to export it to a CSV file but query analyzer dosn't put in the header column, tried to run query through excel but it didn't like my cast statement. Tried through export wizard but it didn't like my multiple alias. Tried to save to file but the format wasn't CSV.

How would i run the qeury and save the result to a csv with column headers? Query is below

SELECT
c.MrMs,
c.First_Name,
c.Initial,
c.owner_id,
(cast (c.Client_Id as varchar (24)))+(cast (c.Contact_Number as varChar(2))) 'KEY',
c.salutation,
c.Phone_1,
c.Phone_1_Extension,
c.Phone_2,
c.Phone_2_Extension,
c.Phone_3,Phone_3_Extension,
c.Phone_4,Phone_4_Extension,
c.Address_Line_1,
c.Address_Line_2,
c.City,State_Province,
c.Zip_Code,
c.Country,
email.AlphaNumericCol,
webpage.AlphaNumericCol,
comments.AlphaNumericCol,
reffered.AlphaNumericCol,
FMC.AlphaNumericCol,
clientlunch.AlphaNumericCol,
officeopening.AlphaNumericCol,
AssetsMil.numericcol,
assetsaffiliation.numericcol,
privclientassets.numericcol,
PortMGR.Description,
Structure.Description,
PlanType.Description,
Mailings.Description,
TypeofOrg.Description,
ClientType.Description,
CompIndStatus.Description,
PersInterests.Description,
ProspectStat.Description,
ReferalSource.Description,
SourceOfWealth.Description,
PrvClientWinLoss.Description,
ShortList.Description,
PensionUseIndexFund.Description,
Contact_type.Description,
InflLunch.Description,
n.textcol


FROM AMGR_Client C

left outer join amgr_user_fields uf on
c.client_Id = uf.Client_Id and
c.contact_number = uf.contact_number

-------------------AlpahaNumeric--------------------------

left outer join amgr_user_fields email on
c.client_id = email.client_id and
c.contact_number = email.contact_number and
email.type_id = 58850

left outer join amgr_user_fields webpage on
c.client_id = webpage.client_id and
c.contact_number = webpage.contact_number and
webpage.type_id = 58851

left outer join amgr_user_fields comments on
c.client_id = comments.client_id and
c.contact_number = comments.contact_number and
comments.type_id = 22

left outer join amgr_user_fields reffered on
c.client_id = reffered.client_id and
c.contact_number = reffered.contact_number and
reffered.type_id = 4

left outer join amgr_user_fields FMC on
c.client_id = FMC.client_id and
c.contact_number = FMC.contact_number and
FMC.type_id = 52

left outer join amgr_user_fields clientlunch on
c.client_id = clientlunch.client_id and
c.contact_number = clientlunch.contact_number and
clientlunch.type_id = 54

left outer join amgr_user_fields officeopening on
c.client_id = officeopening.client_id and
c.contact_number = officeopening.contact_number and
officeopening.type_id = 55

-------------------Numeric--------------------------

left outer join amgr_user_fields AssetsMil on
c.client_id = AssetsMil.client_id and
c.contact_number = AssetsMil.contact_number and
AssetsMil.type_id = 67

left outer join amgr_user_fields assetsaffiliation on
c.client_id = assetsaffiliation.client_id and
c.contact_number = assetsaffiliation.contact_number and
assetsaffiliation.type_id = 7

left outer join amgr_user_fields privclientassets on
c.client_id = privclientassets.client_id and
c.contact_number = privclientassets.contact_number and
privclientassets.type_id = 33

-------------------Table--------------------------

left outer join amgr_user_field_defs PortMGR on
uf.type_id = portMGR.type_id and
uf.code_id = portMGR.code_id and
portMGR.type_id = 19

left outer join amgr_user_field_defs Structure on
uf.type_id = Structure.type_id and
uf.code_id = Structure.code_id and
Structure.type_id = 6

left outer join amgr_user_field_defs PlanType on
uf.type_id = PlanType.type_id and
uf.code_id = PlanType.code_id and
PlanType.type_id = 32

left outer join amgr_user_field_defs Mailings on
uf.type_id = Mailings.type_id and
uf.code_id = Mailings.code_id and
Mailings.type_id = 3

left outer join amgr_user_field_defs TypeofOrg on
uf.type_id = TypeofOrg.type_id and
uf.code_id = TypeofOrg.code_id and
TypeofOrg.type_id = 1

left outer join amgr_user_field_defs ClientType on
uf.type_id = ClientType.type_id and
uf.code_id = ClientType.code_id and
ClientType.type_id = 9

left outer join amgr_user_field_defs CompIndStatus on
uf.type_id = CompIndStatus.type_id and
uf.code_id = CompIndStatus.code_id and
CompIndStatus.type_id = 14

left outer join amgr_user_field_defs PersInterests on
uf.type_id = PersInterests.type_id and
uf.code_id = PersInterests.code_id and
PersInterests.type_id = 23

left outer join amgr_user_field_defs ProspectStat on
uf.type_id = ProspectStat.type_id and
uf.code_id = ProspectStat.code_id and
ProspectStat.type_id = 40

left outer join amgr_user_field_defs ReferalSource on
uf.type_id = ReferalSource.type_id and
uf.code_id = ReferalSource.code_id and
ReferalSource.type_id = 44

left outer join amgr_user_field_defs SourceOfWealth on
uf.type_id = SourceOfWealth.type_id and
uf.code_id = SourceOfWealth.code_id and
SourceOfWealth.type_id = 45

left outer join amgr_user_field_defs PrvClientWinLoss on
uf.type_id = PrvClientWinLoss.type_id and
uf.code_id = PrvClientWinLoss.code_id and
PrvClientWinLoss.type_id = 47

left outer join amgr_user_field_defs ShortList on
uf.type_id = ShortList.type_id and
uf.code_id = ShortList.code_id and
ShortList.type_id = 48

left outer join amgr_user_field_defs PensionUseIndexFund on
uf.type_id = PensionUseIndexFund.type_id and
uf.code_id = PensionUseIndexFund.code_id and
PensionUseIndexFund.type_id = 61

left outer join amgr_user_field_defs Contact_type on
uf.type_id = Contact_type.type_id and
uf.code_id = Contact_type.code_id and
Contact_type.type_id = 109

left outer join amgr_user_field_defs InflLunch on
uf.type_id = InflLunch.type_id and
uf.code_id = InflLunch.code_id and
InflLunch.type_id = 38

-------------------Notes--------------------------

left outer join amgr_notes n on
c.client_id = n.client_id and
c.contact_number = n.contact_number


where c.record_type in (1,2,31,32)
 
Select Options from the tools menu in query analyzer.
Select the Results tab.
Select Results Output Format as "Comma Delimited (CSV)"
Select the Print Column Headers checkbox.

Now try it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top