Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using quotes in a string
Message
 
 
À
18/10/2012 12:26:07
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01555242
Message ID:
01555253
Vues:
26
>>>so, if I'm understanding you - I need to have
>>>
>>>
>>>Set @BulkCmd = 'Bulk Insert qryICECLImport from ' + @filename + ' with (FieldTerminator = '','', RowTerminator = ''\n'')'
>>>
>>>
>>>Where the '' is actually 2 single quotes?
>>>
>>Yes. You can always add print @BulkCmd to see it.
>
>Yeah, I do that for things like this to make sure they 'look' right.
>Here's what I'm working with:
>
>declare @filename nvarchar(50), @BulkCmd nvarchar(200)
>Set @filename = 'c:\download\dropbox\cat\qryICECLExport.csv'
>set @BulkCmd = 'Bulk Insert qryICECLExport
>    from ' + '' +  @filename  + '' +  
>    ' with (FieldTerminator = '','', RowTerminator = ''\n'')'
>print @BulkCmd
>exec(@BulkCmd)
>
>** and the messages I get when I execute the above block
>Bulk Insert qryICECLExport
>    from c:\download\dropbox\cat\qryICECLExport.csv with (FieldTerminator = ',', RowTerminator = '\n')
>
>Msg 102, Level 15, State 1, Line 2
>Incorrect syntax near 'c:'.
>Msg 319, Level 15, State 1, Line 2
>Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
>
>The only thing I'm seeing that's probably not correct is that there should be quotes around the c:\.... I've tried
>
>Set @FileName = '' + 'c:\...csv' + ''
>
>but that doesn't put the quotes around it either.

Try
declare @filename nvarchar(50), @BulkCmd nvarchar(200)
Set @filename = 'c:\download\dropbox\cat\qryICECLExport.csv'
set @BulkCmd = 'Bulk Insert qryICECLExport
    from " ' + @filename  + 
    '" with (FieldTerminator = '','', RowTerminator = ''\n'')'
print @BulkCmd
exec(@BulkCmd)
In other words, try putting file name in double quotes.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform