Solved

Unknown argument 'ùU' on command line.

Posted on 2004-09-08
7
877 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
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 backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

863 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

26 Experts available now in Live!

Get 1:1 Help Now