Export problemer (BCP) i en stored procedure
Hej EksperterEr kørt fast med min stored procedure.
Jeg skal exportere data fra flere tabeller i min database.
De skal eksporteres som en .csv fil eller lign.
Jeg får følgende fejl:
SQLState = 37000, NativeError = 102
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'a47'. SQLState = 37000, NativeError = 8180 Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
Det er mit GroupID der driller.
Min stored Procedure ser ud som følger:
ALTER PROCEDURE dbo.ExportOrderList2
@FileOutputName as varchar(max),
@GroupID as varchar(max) = "b12cb2c0-8a47-4fb0-ac00-55ffeb578a46"
AS
DECLARE @FileName varchar(50),
@bcpCommand varchar(2000),
@tmpGroupID varchar(100),
@TmpCommand varchar(max)
SET @FileName = 'e:\websites\import\'+@FileOutputName+'.csv'
SET @bcpCommand =
'bcp "'
+'SELECT UsrFName, UsrLName, usraddress, ASPNET_Users.ZIP, City, usremail, usrcellphone, usrphone, ProductName FROM MyDB..MainOrder '
+'INNER JOIN MyDB..AspNet_Users ON MyDB..MainOrder.UsrID = MyDB..AspNet_Users.UserID '
+'INNER JOIN MyDB..ZIPCodes ON MyDB..AspNet_Users.ZIP = MyDB..ZipCodes.ZIP '
+'INNER JOIN MyDB..Orderline ON MyDB..MainOrder.MainOrderID = MyDB..Orderline.MainOrderID '
+'INNER JOIN MyDB..Product ON MyDB..Orderline.ProductID = MyDB..Product.ProductID '
+'WHERE MyDB..AspNet_Users.GroupID='+@GroupID + ' '
+'" queryout "'
SET @bcpCommand = @bcpCommand + @FileName + '" -c -t; -k -C1252'
EXEC master..xp_cmdshell @bcpCommand
print @bcpcommand
RETURN
Følgende udskrives når jeg tester:
bcp "SELECT UsrFName, UsrLName, usraddress, ASPNET_Users.ZIP, City, usremail, usrcellphone, usrphone, ProductName FROM MyDB..MainOrder INNER JOIN MyDB..AspNet_Users ON MyDB..MainOrder.UsrID = MyDB..AspNet_Users.UserID INNER JOIN MyDB..ZIPCodes ON MyDB..AspNet_Users.ZIP = MyDB..ZipCodes.ZIP INNER JOIN MyDB..Orderline ON MyDB..MainOrder.MainOrderID = MyDB..Orderline.MainOrderID INNER JOIN MyDB..Product ON MyDB..Orderline.ProductID = MyDB..Product.ProductID WHERE MyDB..AspNet_Users.GroupID=b12cb2c0-8a47-4fb0-ac00-55ffeb578a46 " queryout "e:\websites\import\ExportedFile.csv" -c -t; -k -C1252
Er der nogen der kan se hvad der går galt?
På forhånd tak.