on 2011 Aug 18 4:17 PM
The first statement below works correctly:
unload select 1 to 'c:\\temp\\test.txt' delimited by ',' quotes off escapes off
The next statement does not work correctly. The difference is I am passing in the now() function to put a timestamp in the file name:
unload select 1 to 'c:\\temp\\test_'||now()||'.txt' delimited by ',' quotes off escapes off
I can't figure out how to string together the directory and path on the unload to command. The problem is not the now() function because even this does not work:
unload select 1 to 'c:\\temp\\test_'||'test'||'.txt' delimited by ',' quotes off escapes off
Any ideas?
Request clarification before answering.
Make the path/filename a variable like so:
begin declare @path varchar(50); set @path = 'c:/temp/test_' + string(dateformat(now(), 'yyyy-mm-dd-hh-mm')) + '.txt'; unload select 1 to @path delimited by ',' quotes off escapes off end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Seems to be stripping out the the extra backslashes in the path when I post.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
actually this is what I had (the extra back slashes)...
begin declare @path varchar(50); set @path = '\\\\myserver\\temp\\test_' + string(dateformat(now(), 'yyyy-mm-dd-hh-mm')) + '.txt'; unload select 1 to @path delimited by ',' quotes off escapes off end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Vincent. I do want to take this one step further though, and send the file to a network drive. The following is the syntax I am using. I am not getting an error, but it is not writing the file to the place I need it to go. Does this syntax appear correct? Not sure if it is syntax or permissions.
begin declare @path varchar(50); set @path = '\\\\myserver\\temp\\test_' + string(dateformat(now(), 'yyyy-mm-dd-hh-mm')) + '.txt'; unload select 1 to @path delimited by ',' quotes off escapes off end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In case permissions are the problem, much more information and several approaches can be found in this FAQ.
User | Count |
---|---|
74 | |
20 | |
9 | |
8 | |
7 | |
5 | |
5 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.