?
Solved

Unknown argument 'ùU' on command line.

Posted on 2004-09-08
7
Medium Priority
?
969 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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 2000 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

800 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