Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

insert headers into sql query results Expand / Collapse
Author
Message
Posted Thursday, September 17, 2009 10:00 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 23, 2009 1:55 PM
Points: 6, Visits: 29
Hi ,

I am new to TSql and need to add dummy headers to my sql result before i export it to a csv format.

i can have a header which can be a noddy as '1' or 'header' as the macro that need to read my result start reading data from the 3rd row

Many thanks,

Christian
Post #789787
Posted Thursday, September 17, 2009 10:25 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, February 9, 2010 2:41 AM
Points: 140, Visits: 1,019
If that's the way your tool reds CSV I suggest you find fome other tool, but as per your question, you may append dummy lines in the following way: Suppose you have a list of names and their phone numbers, returned by this fictious query:

Select PersonName, Phone From MyPhoneBook

You could add your 2 dummy lines in the following way:
Select '' AS PersonName, '' AS Phone 
UNION ALL
Select '', ''
UNION ALL
Select PersonName, Phone From MyPhoneBook



Tal Ben Yosef
www.TalBenYosef.com
(visit my LinkedIn profile)

Post #790107
Posted Friday, September 18, 2009 3:37 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 23, 2009 1:55 PM
Points: 6, Visits: 29
Thanks for you response, this will work for my initial question. Unfortunatly i have about 70 columns, is there a short way of doinf this without clobbering the sql codes with empty strings?

i know that its can be done in excel but was wondering if there is a sql statement that does it inside sql server
Post #790209
Posted Friday, September 18, 2009 6:08 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, February 9, 2010 2:41 AM
Points: 140, Visits: 1,019
It really depends on many parameters, but as a rule of thumb - check if you need to apply this fix in many views or procedures and if all solutions are the same. If so, you might wanna forget about touching the SQL code and opting for external solutions that wil simply add those 2 empty lines in the beginning of your file.

Some of the available tools for that could be:
1. CMD --> type 2 empty lines and then your original files into a new CSV file (however, you might need the commas. I don't know which tool are you using to read your CSV files)

2. LOGPARSER --> You can use Microsoft's LogParser to do the same thing you wanted SQL to

3. Use CSCRIPT (JS / VBSCRIPT) to append replicate the first two lines

etc...


Tal Ben Yosef
www.TalBenYosef.com
(visit my LinkedIn profile)

Post #790309
Posted Friday, September 18, 2009 1:23 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 23, 2009 1:55 PM
Points: 6, Visits: 29
Thanks Ben,

I am using SSIS, i can use vbcrlf cmd in access but we are trying to move away from that.

thanks,

Chris
Post #790663
Posted Saturday, September 19, 2009 12:58 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, February 9, 2010 2:41 AM
Points: 140, Visits: 1,019
Although I owe much of my com[puter life to mictosoft Access, I think it's a smart decision to move away from that.

You're either gonna deal with the CSV producer or the consumer....

One more choice came to my mind: Unix SED command. It has a Win32 port. It's really powerful!

Sed man page


Tal Ben Yosef
www.TalBenYosef.com
(visit my LinkedIn profile)

Post #790758
Posted Tuesday, September 22, 2009 3:01 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 23, 2009 1:55 PM
Points: 6, Visits: 29
Thanks Ben,

i guess for the time being i will stick with access before experiemnting with other products.

Thank you for your contribution

C
Post #791592
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse