February 16, 2006 at 4:42 pm
Hi All,
A newbie here.
I'm using osql to generate a comma delimited file but the column data is padded with spaces. Would like to get the same formatting as when saving Query Analyzer's grid results as a .csv - namely that all padding is suppressed. Have googled until brain dead.
Any and all help is greatly appreciated.
February 16, 2006 at 5:55 pm
char() columns will pad the data with blanks. An easy solution would be to use the RTRIM() function to remove the spaces.
February 17, 2006 at 6:01 am
or mess with ansi padding
declare @tb table (col1 int identity(1,1) primary key
, mychar10 char(10) not null default('a')
, myvarchar10 varchar(10) not null default('b') );
set nocount on;
insert into @tb default values;
insert into @tb default values;
insert into @tb default values;
insert into @tb default values;
insert into @tb default values;
insert into @tb default values;
set nocount off;
SET ANSI_PADDING ON ;
select cast(col1 as varchar(10))
+ ',' + mychar10
+ ',' + cast(mychar10 as varchar(10))
+ ',' + myvarchar10
+ ',' + rtrim(mychar10) + ', end'
from @tb;
SET ANSI_PADDING OFF ;
select cast(col1 as varchar(10))
+ ',' + mychar10
+ ',' + cast(mychar10 as varchar(10))
+ ',' + myvarchar10
+ ',' + rtrim(mychar10) + ', end'
from @tb;
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
February 17, 2006 at 11:44 am
It's looking like I don't have much choice but to build the output using rtrim()+",". Didn't want to have to resort to this but it seems osql uses a predefined column size regardless of the actual size in the table. In that same vein ansi_padding doesn't help either (and don't want to have to rebuild the tables either - call me lazy). It would have been nice to use the same queries built for Query Analyzer but alas.
Thanks for you help guys!
February 19, 2006 at 11:57 pm
Did you take a look as to how DTS may help you to solve this problem ?
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
February 20, 2006 at 10:28 am
Not yet. Started reading up but it seemed like something I just don't have the time to play with and figure out at the moment - seems to have a lot of bells and whistles. Eventually though cause it does sound promising.
February 21, 2006 at 12:03 am
it's _the_ way for importing / exporting data.
Even the wizard is intuitive
EM (enterprise manager) \ databases \tables got to the righthand side, right-click and choose ALL tasks \ import or Export data
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
February 21, 2006 at 2:39 pm
have used the wizard a couple of times and must agree it's very friendly. however, i'm involved in a conversion/consolidation project that is centralizing several community colleges. we're having to reload our target databases constantly as we treak the process so it would be nice to run these extracts via something like a bat file - one click and i'm done - which is why i was looking at osql. does dts have a command line interface callable from a bat file? hate asking this question w/o doing more digging but since i have your ear...
February 22, 2006 at 11:48 pm
Yes it has.
In fact, you can prepare and save your package (if you used the wizard, you must have seen the panel where it asks "run immediate , save as ..." .
This saved package can then be scheduled as a sqlagent job and run frequently.
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
February 23, 2006 at 3:56 pm
Excellent! Just never made the connection between "save as" and running it as an agent. Like I said, I'm a rookie. It appears I have some reading to do this weekend. Enjoy and thanks much!
Viewing 10 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply