J'ai des problèmes avec le message d'erreur "Syntaxe incorrecte près de 'queryout'." La cible consiste à extraire les fichiers de données d'une base de données vers un serveur. Les problèmes semblent se trouver dans le fichier de requête. Mais je ne sais pas où.bcp Syntaxe incorrecte près de 'queryout'
DECLARE @DBName VARCHAR(5000);
DECLARE @period VARCHAR(5000);
DECLARE @SQLEXE VARCHAR(8000);
DECLARE @SearchSchema NVARCHAR(4000);
SET @period = '''2017-01-01 00:00:00'' AND ''2017-12-31 23:59:59'''
SET @DBName = (SELECT name FROM master.dbo.sysdatabases where name LIKE '%NAV%');
EXECUTE ('USE [' + @DBName+']'); Select db_name();
SET @SearchSchema = (SELECT REPLACE(name,'Change Log Setup', 'Change Log Entry') as Name FROM [Demo Database NAV (10-0)].sys.tables where name LIKE '%$Change Log Setup');
PRINT '@SearchSchema: ' + @SearchSchema;
SET @SQLEXE = 'bcp SELECT [Entry No_]
,[Date and Time]
,[User ID]
,[Table No_]
,[Field No_]
,[Type of Change]
,[Old Value]
,[New Value]
,[Primary Key]
,[Primary Key Field 1 No_]
,[Primary Key Field 1 Value]
,[Primary Key Field 2 Value]
,[Primary Key Field 3 No_]
,[Primary Key Field 3 Value]
,[Record ID]
FROM [' + @DBName + '].[dbo].[' + @SearchSchema + ']
WHERE [Date and Time] BETWEEN '[email protected]+' queryout C:\Users\Public\Documents\1a_EY_change_log_entry.txt -c-T'
PRINT 'SQLEXE ' + @SQLEXE;
Exec (@SQLEXE);
La sortie Imprimer @SQLEXE ist:
SQLEXE bcp SELECT [Entry No_]
,[Date and Time]
,[User ID]
,[Table No_]
,[Field No_]
,[Type of Change]
,[Old Value]
,[New Value]
,[Primary Key]
,[Primary Key Field 1 No_]
,[Primary Key Field 1 Value]
,[Primary Key Field 2 Value]
,[Primary Key Field 3 No_]
,[Primary Key Field 3 Value]
,[Record ID]
FROM [Demo Database NAV (10-0)].[dbo].[CRONUS International Ltd_$Change Log Entry]
WHERE [Date and Time] BETWEEN '2017-01-01 00:00:00' AND '2017-12-31 23:59:59' queryout C:\Users\Public\Documents\1a_EY_change_log_entry.txt -c-T
Message d'erreur:
Msg 102, Level 15, State 1, Line 17
Incorrect syntax near 'queryout'.
Si je change la commande en
EXEC xp_cmdshell @SQLEXE;
GO
le résultat est:
Le sens de la copie doit être 'in', 'out' ou 'format'.
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]
[-d database name] [-K application intent] [-l login timeout]
NULL
'EXEC' exécutera du code SQL, pas exécuter une ligne de commande. – DavidG
Ce poste est un doublon de https://stackoverflow.com/questions/45073064/problems-with-bcp-output/45073531?noredirect=1#comment77233470_45073531, l'auteur est le même – sepupic
duplication possible de [Problèmes avec sortie bcp] (https://stackoverflow.com/questions/45073064/problems-with-bcp-output) – DavidG