Solved

Unknown argument 'ùU' on command line.

Posted on 2004-09-08
7
895 Views
Last Modified: 2010-08-05
I get this error when I try to run this script can you tell me what I am doing wrong.  Thanks Unknown argument 'ùU' on command line.



-- Populate Temp Database with information from Text File
BULK INSERT DOCSDB..Temp FROM 'c:\SER\test.txt'
WITH (
   DATAFILETYPE = 'char',
   FIELDTERMINATOR = ',',
   ROWTERMINATOR = '\n'
)

--Declare variables
declare @DB_NAME varchar(128)
declare @DB_Match varchar(128)
declare @ColNameSearchingFor varchar(128)
declare @TabName varchar (128)
declare @tablen varchar (128)
--declare cursor
declare SERCur cursor
--Start Loop
for
--Select table name when starts with vtab and add to cursor
     select table_name from information_schema.tables where table_name like 'vtab%'
--open cursor
open SERCur
--Get First record in cursor and save to variable DB_NAME
fetch next from SERCur into @DB_NAME
--Loop unti end of records in cursor
while @@FETCH_STATUS = 0
     begin

     set @TabName = @DB_Name + '.val'
     Declare @script varchar(8000)
 


     --Select account and date from database
Set @script = 'BCP "SELECT distinct'  + @TabName + ' FROM ' + @DB_NAME + ', TEMP  where ' + @TabName + ' = TEMP.val"  queryout Account.txt —U sa —P cfds —S —c'

Exec master.dbo.xp_cmdshell @script

       
               --get next table name from cursor
         fetch next from SERCur into @DB_NAME
           
     end



--Close Cursor
close SERCur
deallocate SERCur
0
Comment
Question by:running32
  • 3
  • 3
7 Comments
 
LVL 34

Expert Comment

by:arbert
ID: 12008981
It looks like there are some special characters--when I copy and past I get one dash in front of your U and S, but that's not what's displayed above--try this:

Set @script = 'BCP "SELECT distinct'  + @TabName + ' FROM ' + @DB_NAME + ', TEMP  where ' + @TabName + ' = TEMP.val"  queryout Account.txt -U sa -P cfds -S -c'


0
 
LVL 12

Expert Comment

by:kselvia
ID: 12009130
I don't know if it really matters but I think there is a limit for the length of a DOS command line so change varchar(8000) to varchar(255) and you probably need a space after distinct here: 'SELECT distinct'

Also, it looks like the select would evaluate to something like

SELECT distinct vtab_xyz.val from vtab_xyz, TEMP Where vtab_xyz = TEMP.val

Your cursor is not really retrieving a database into @DB_NAME it is retrieving the table name, so there would be no dbname.dbo.tablename in your select either, and what is the comma before TEMP there for.

Or maybe it's just my eyes today...

0
 

Author Comment

by:running32
ID: 12010672
If I run this it just says (382 row(s) affected)  but no file is output.   Where who file file go I am on the server?
Thanks



-- Populate Temp Database with information from Text File
BULK INSERT DOCSDB..Temp FROM 'c:\SER\test.txt'
WITH (
   DATAFILETYPE = 'char',
   FIELDTERMINATOR = ',',
   ROWTERMINATOR = '\n'
)

--Declare variables
declare @DB_NAME varchar(128)
declare @DB_Match varchar(128)
declare @ColNameSearchingFor varchar(128)
declare @TabNamec varchar (128)
declare @TabName varchar (128)
declare @tablen varchar (128)
--declare cursor
declare SERCur cursor
--Start Loop
for
--Select table name when starts with vtab and add to cursor
     select table_name from information_schema.tables where table_name like 'vtab%'
--open cursor
open SERCur
--Get First record in cursor and save to variable DB_NAME
fetch next from SERCur into @DB_NAME
--Loop unti end of records in cursor
while @@FETCH_STATUS = 0
     begin
     set @TabName = @DB_Name
     set @TabNamec = @DB_Name + '.val'
     Declare @script varchar(255)
 


     --Select account and date from database
--Set @script = 'BCP "SELECT distinct val FROM ' + @DB_NAME + ', TEMP  where ' + @TabNamec + ' = TEMP.val"  queryout Account.txt -U sa -P cfds -S -c'
Set @script = 'BCP "SELECT distinct val FROM' + @DB_Name + ' where ' + @TabNamec + ' = TEMP.val"  queryout c:\Account.txt -U sa -P cfds -S -c'

Exec master.dbo.xp_cmdshell @script

       
               --get next table name from cursor
         fetch next from SERCur into @DB_NAME
           
     end



--Close Cursor
close SERCur
deallocate SERCur


0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 34

Expert Comment

by:arbert
ID: 12010694
based upon your query, it should be on the C: of the SQL Server box....
0
 

Author Comment

by:running32
ID: 12010731
I'm on the sql box but I do not see it.  How would I tell if it is outputting anything?

thanks
0
 

Author Comment

by:running32
ID: 12011449
Because I am running against the master database it does not reconize the vtab001 table or temp table.  How can I fix this please?

SQLState = 37000, NativeError = 107
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]The column prefix 'VTAB0001' does not match with a table name or alias name used in the query.
SQLState = 37000, NativeError = 107
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]The column prefix 'TEMP' does not match with a table name or alias name used in the query.
SQLState = 37000, NativeError = 8180
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
NULL
0
 
LVL 34

Accepted Solution

by:
arbert earned 500 total points
ID: 12011925
add a

USE YOURDATABASE

at the beginning to switch to the database you want to use.  Either that, or use the fully qualified name of the objects:

database.owner.table
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question