2012年2月18日星期六

BCP - File generate and name HELP

Hi All
I am trying to generate and name a file with the
following syntax : but get Error: 'bcpSelect' is not
recognized as an internal or external command,
DECLARE @.A char(100)
DECLARE @.str varchar(200)
DECLARE @.B Char(100)
DECLARE @.Con varchar(500)
Select @.Con = DataCon from FileNameCreate
Select @.A = SerialNo from FileNameCreate
Select @.B = 'Select * from FileNameCreate + +'
Select @.str='bcp' + @.B + 'queryout c:\Lut' + @.A + '.txt -
c -Usa -P -SUKLUN005\UKLUS0004H'
EXEC master..XP_cmdshell @.str"Brian" <anonymous@.discussions.microsoft.com> wrote in message
news:09e701c3a606$1561a040$a301280a@.phx.gbl...
> Hi All
> I am trying to generate and name a file with the
> following syntax : but get Error: 'bcpSelect' is not
> recognized as an internal or external command,
>
> DECLARE @.A char(100)
> DECLARE @.str varchar(200)
> DECLARE @.B Char(100)
> DECLARE @.Con varchar(500)
> Select @.Con = DataCon from FileNameCreate
> Select @.A = SerialNo from FileNameCreate
> Select @.B = 'Select * from FileNameCreate + +'
> Select @.str='bcp' + @.B + 'queryout c:\Lut' + @.A + '.txt -
> c -Usa -P -SUKLUN005\UKLUS0004H'
> EXEC master..XP_cmdshell @.str
You need to leave additional spaces in your command string, and you also
need double quotes around a query used with BCP:
select @.str = 'bcp "' + @.B + '" queryout...'
If you're building dynamic strings to execute, it usually helps to 'SELECT
@.str' just before you execute it, at least during development, to make sure
that the command is being built as you expect.
Simon|||Hi Simon
I have edited the file like this: and get error: SQLState
= 37000, NativeError = 170
Error = [Microsoft][ODBC SQL Server Driver]
[SQL Server]Line 1: Incorrect syntax near 'Test2'.
Test2 is correct information from the table....
DECLARE @.A char(100)
DECLARE @.str varchar(200)
DECLARE @.B Char(100)
Select @.B = Datacon from FileNameCreate
Select @.A = SerialNo from FileNameCreate
Select @.str = 'bcp "'+ @.B +'" queryout "c:\Lut.txt" -c -
Usa -P -"SUKLUN005\UKLUS004H"'
EXEC master..XP_cmdshell @.str|||Brian,
> I have edited the file like this: and get error: SQLState
> = 37000, NativeError = 170
> Error = [Microsoft][ODBC SQL Server Driver]
> [SQL Server]Line 1: Incorrect syntax near 'Test2'.
> Test2 is correct information from the table....
> DECLARE @.A char(100)
> DECLARE @.str varchar(200)
> DECLARE @.B Char(100)
You have declare @.A and @.B as fixed character data type. Change them
to varchar(100).
Then substitute the following for the exec statement:
print @.str
--EXEC master..XP_cmdshell @.st
It will then be obvious what your problems are.
Linda|||Brian;
I'd suggest that you put a print statement after you have constructed the
dynamic SQL and comment out the EXECUTE. Run the script to see what SQL
statement you are getting. When you are satisfied with the SQL statement,
comment out the print statement and uncomment the EXECUTE statement. Often,
this is much quicker to a solution than getting feedback from others.
--
Linchi Shea
linchi_shea@.NOSPAMml.com
"Brian" <anonymous@.discussions.microsoft.com> wrote in message
news:003f01c3a610$76060760$a101280a@.phx.gbl...
> Hi Simon
> I have edited the file like this: and get error: SQLState
> = 37000, NativeError = 170
> Error = [Microsoft][ODBC SQL Server Driver]
> [SQL Server]Line 1: Incorrect syntax near 'Test2'.
> Test2 is correct information from the table....
> DECLARE @.A char(100)
> DECLARE @.str varchar(200)
> DECLARE @.B Char(100)
> Select @.B = Datacon from FileNameCreate
> Select @.A = SerialNo from FileNameCreate
> Select @.str = 'bcp "'+ @.B +'" queryout "c:\Lut.txt" -c -
> Usa -P -"SUKLUN005\UKLUS004H"'
> EXEC master..XP_cmdshell @.str
>|||The Print does help. However i now get the following error
Line 7: Incorrect syntax near 'C:\Lut.txt'.
I have tryed the following:
The file exists.
Using ', " and both.|||This is now corrected by 'queryout C:\Lut.txt'
-S Server name
Now i get: Line 7: Incorrect syntax near 'UKLUN005
\UKLUS004H'.
>--Original Message--
>The Print does help. However i now get the following
error
>Line 7: Incorrect syntax near 'C:\Lut.txt'.
>I have tryed the following:
>The file exists.
>Using ', " and both.
>.
>|||Thanks all
BCP is now working and i am now using it in my live
system..............
>--Original Message--
>This is now corrected by 'queryout C:\Lut.txt'
>-S Server name
>Now i get: Line 7: Incorrect syntax near 'UKLUN005
>\UKLUS004H'.
>
>>--Original Message--
>>The Print does help. However i now get the following
>error
>>Line 7: Incorrect syntax near 'C:\Lut.txt'.
>>I have tryed the following:
>>The file exists.
>>Using ', " and both.
>>.
>.
>

没有评论:

发表评论