• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1022
  • Last Modified:

Unknown argument 'ùU' on command line.

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
running32
Asked:
running32
  • 3
  • 3
1 Solution
 
arbertCommented:
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
 
Ken SelviaRetiredCommented:
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
 
running32Author Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
arbertCommented:
based upon your query, it should be on the C: of the SQL Server box....
0
 
running32Author Commented:
I'm on the sql box but I do not see it.  How would I tell if it is outputting anything?

thanks
0
 
running32Author Commented:
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
 
arbertCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now