Solved

Unknown argument 'ùU' on command line.

Posted on 2004-09-08
7
870 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert int to military time 8 20
Sql query for filter 12 23
Azure SQL DB? 3 21
How toselect unique values 3 10
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now