BCP insert data from cvs insert into sql server table - bcp

I made this BCP code but when i run it dont copy rows "0 rows copied" why?

Related

Bulk Insert text file with additional column

I am using SQL Server 2008 and I have a table that has two columns. One column is for a row of text and the second is for the name of the text file. I am using the command below. This works fine to insert the rows of text but is there any way to also insert the file name test.txt with all the rows?
BULK INSERT viewFile FROM 'C:\test.txt' WITH (ROWTERMINATOR ='\n')

Backup & remove specific records - SQL Server

Is there anyway to:
Remove specific records from the table using a query?
Make a backup from specific records and restore them into another SQL Server instance somewhere else?
1) If ID is the table's PK (or it is unique) you can just use DELETE FROM TABLE_NAME WHERE ID IN (3, 4). You better check if this will not delete other items (or open a transaction, which is always good).
2) If it is just those 4 records and both databases are on the same server (and both tables have the same schema) you can just do (with the same worries that I have expressed in the answer above)
insert into DESTINATION
select * from SOURCE where id between 73 and 76;
Edit: If you really need to do something more like a row backup you can use the bcp utility:
bcp "select * from SOURCE where id between 73 and 76" queryout "file.dat" -T -c
bcp DESTINATION in file.dat -T -c
DELETE FROM ListsItems
WHERE ID = (3, 4);
It will remove your record.
Modify it....

Handling Empty Strings in SQL Bulk Insert

I am using SQL Bulk Insert to insert data into a temporary table.
My table has a column XYZ which is defined as varchar NOT NULL and I want if the XYZ column data in the delimited file is empty, it should be written to error file. Currently SQL BI treats it as a 0 length string and inserts into the table.
The delimited file looks like this:
Col1|XYZ|Col2
abc||abc
abc||abc
abc|abc|abc
I tried using CHECK_CONSTRAINTS in SQL BI query and created a Check constraint on XYZ column in table as XYZ <> '', but rather then writing particular row to error file, it causes the entire SQL BI to fail.
Please help.

Bulk insert in SQL and insert others values

I have one table with 3 fields
id_Complex | fileLine | date
The field id_Complex, and, that id_complex is the same for the file, that id just chenge when another file is processed is a ID generate from my program, fileLine is just a line from file and date is the date of recording of the line.
Now, my program make a insert in the database for each line read from the file.
I whant to know, if is possible to make a bulk, and that bulk just insert the values in one specific column of table, and, I just send the id_complex to sql, so, the SQL will be make the insert with id_complex I sent for SQL, the lines of file and date.
How I can make that bulk ?
it's possible to make this, Bulk insert with one that has a value predefined
You should in your program proccess input file and generate temp file with correct complex_id and the make bulk insert for this temp file.
After insert just delete temp file.
If I understand what you are asking, you could create a temporary table TempTable and do a bulk insert into it. Then perform an UPDATE from TempTable joining to your permanent table by id_Complex. You can also set the date in this UPDATE statement. Finally, clear out the temporary table.
Alternatively, you could bulk import the file into a temporary table, delete the old permanent table, and rename the temporary table as the permanent table.

can't insert records in new table from existing table in sql server 2005

I need to insert records into a new table from an existing table. I used the following query to do this:
Insert into Newtable
Select * from Oldtable where date1 = #date
This query works most of the time, but in one scenario I get 10 million records to be inserted for the date1 value. In this case I'm getting the following error message:
Error : The transaction log for database "tempDB" is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases
Should I break the query into parts and insert them sequentially, or is there a way to do this with the current query?
This is, perhaps, a distasteful suggestion. But, you can try exporting the data to a file and then inserting using bulk-insert, with database logging set to SIMPLE or BULK-LOGGED.
More information is at http://msdn.microsoft.com/en-us/library/ms190422.aspx.