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.
| Author |
Topic |
|
cosuji
Starting Member
3 Posts |
Posted - 2008-12-11 : 11:33:17
|
| Hi there,I am trying to use a stored procedure on SQL Server 2005 to write an .xml file to a folder, but am having problems with the bcp command I am using (I think).The SELECT statement inside the bcp command produces the desired result, so I have a feeling it is the bcp bit that is incorrect.Would anyone be able to kindly point out where I am going wrong? I would be most grateful for any help. My code looks like this:DECLARE @bcpCommand VARCHAR(1000)DECLARE @fileName VARCHAR (50)-- Path to the website folder where file will be storedSET @fileName = 'C:\Temp\test\test_Sitemap.xml'-- Selects the URL from the page table and replaces the tilda '~' with 'http://' in order to build a recognisable URL (e.g. 'http://www.XXX.co.uk/login.aspx'). Also selects the timestamp of the last modification of a website pageSET @bcpCommand = 'bcp "SET QUOTED_IDENTIFIER OFF SELECT DISTINCT dbo.fnEncodeURL("http://www.XXX.co.uk" + REPLACE( Page.Url, "~", "" )) AS loc, convert( char(10), Page_Audit.ActionDateTime, 103 ) AS lastmod, "weekly" AS changefreq, 0.5 AS priority FROM Page INNER JOIN Page_Audit ON Page.ID = Page_Audit.ID FOR XML PATH ("url"),ELEMENTS,ROOT("urlset") SET QUOTED_IDENTIFIER ON" queryout "'SET @bcpCommand = @bcpCommand + @fileName + '" -c -x -T'ENDMany thanks,Chima |
|
|
cosuji
Starting Member
3 Posts |
Posted - 2008-12-11 : 11:45:57
|
| Ah, silly me I had not included:-- Run the commandEXEC master..xp_cmdshell @bcpCommandHowever I'm getting errors all over the place now.SQLState = 42000, NativeError = 102Error = [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near 'http:'.SQLState = 42000, NativeError = 105Error = [Microsoft][SQL Native Client][SQL Server]Unclosed quotation mark after the character string ' )) AS loc, convert( char(10), Page_Audit.ActionDateTime, 103 ) AS lastmod, weekly AS changefreq, 0.5 AS priority FROM Page INNER JOIN Page_Audit ON Page.ID = Page_Audit.ID FOR XML PATH (url),ELEMENTS,ROOT(urlset) SET QUOTED_IDENTIFIER ON'.SQLState = 42000, NativeError = 8180Error = [Microsoft][SQL Native Client][SQL Server]Statement(s) could not be prepared. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
cosuji
Starting Member
3 Posts |
Posted - 2008-12-12 : 05:14:27
|
| Hi,I have tweaked the code a little bit, and when printed it displays:bcp "SELECT DISTINCT dbo.fnEncodeURL('http://www.XXX.co.uk' + REPLACE( Page.Url, '~', '' ))AS loc, convert( char(10), Page_Audit.ActionDateTime, 103 ) AS lastmod, 'weekly' AS changefreq, 0.5 AS priority FROM Page INNER JOIN Page_Audit ON Page.ID = Page_Audit.ID FOR XML PATH ('url'),ELEMENTS,ROOT('urlset')" queryout "C:\Temp\test\test_Sitemap.xml" -c -x -TWhen I execute the stored procedure, however, all I get is this:usage: bcp {dbtable | query} {in | out | queryout | format} datafile [-m maxerrors] [-f formatfile] [-e errfile] [-F firstrow] [-L lastrow] [-b batchsize] [-n native type] [-c character type] [-w wide character type] [-N keep non-text native] [-V file format version] [-q quoted identifier] [-C code page specifier] [-t field terminator] [-r row terminator] [-i inputfile] [-o outfile] [-a packetsize] [-S server name] [-U username] [-P password] [-T trusted connection] [-v version] [-R regional enable] [-k keep null values] [-E keep identity values] [-h "load hints"] [-x generate xml format file]NULLWould anyone be able to kindly shed some light on this?Many thanks,ChimaPS. Code is now: -- Selects the URL from the page table and replaces the tilda '~' with 'http://www.bwellbirmingham.co.uk' -- in order to build a recognisable URL (e.g. 'http://www.bwellbirmingham.co.uk/login.aspx'). Also selects -- the timestamp of the last modification of a website pageSET @bcpCommand = 'bcp "SELECT DISTINCT dbo.fnEncodeURL(''http://www.XXX.co.uk'' + REPLACE( Page.Url, ''~'', '''' ))AS loc,convert( char(10), Page_Audit.ActionDateTime, 103 ) AS lastmod,''weekly'' AS changefreq, 0.5 AS priorityFROM Page INNER JOIN Page_Audit ON Page.ID = Page_Audit.IDFOR XML PATH (''url''),ELEMENTS,ROOT(''urlset'')" queryout "'SET @bcpCommand = @bcpCommand + @fileName + '" -c -x -T' |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|
|