Bulk Insert Multiple Pipe Data in Table - sql

I wrote a query to insert data from .lst file into table name AxisATM But when i try to insert it gives me error that
WHEN I REMOVES ALL ROWS FROM LST file except First ..It gives me Success msg saying 1 rows changed..
Msg 4866, Level 16, State 1, Line 1
The bulk load failed. The column is too long in the data file for row 1, column 36. Verify that the field terminator and row terminator are specified correctly.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
Query :-
BULK
INSERT dbo.ATMAxis
FROM 'c:\AGS_WINCORE_120901.lst'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = 'CHAR(13)'
)
GO
AGS_WINCORE_120901.lst :-
PRO1|......|00000000000|0| {Like it has 36 '|' separators}
Using Notepad++ i know Line End Characters are CR LF

As expected the problem lies in
ROWTERMINATOR = 'CHAR(13)'
I have Changed it to
ROWTERMINATOR = '0x0A'

As the error says column 36 has more chanracters than that of column 36 of table's column. You need to increase the size of that column

It seems the row terminator creates issue. If that's the case, try replacing /r/n with Char(10) it will solve the problem. Also, check for char(13).
This MSDN thread has more information.

Related

DELETING NULL ERROR MSG APPEARING

I am trying to delete away all the rows with NULL. I tried using the code:
DELETE FROM [FILENAME] WHERE [MONTH] = 'NULL'
But the error msg appears as:
Msg 241, Level 16, State 1, Line 1 Conversion failed when converting
date and/or time from character string.
I'm guessing i have to convert something but got no clue. Any help will be great. thanks
The error is because (NULL) is not a value and not a string value to put it between two single quotation marks('').
NULLs have special ways and special functions to deal with it, so you can use this code to delete away all the rows with NULL
DELETE FROM [FILENAME] WHERE [MONTH] IS NULL

SQL query is throwing this error Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ' '

Query is :
select * from Test.dbo.Test_Spoc where spocNo = 54986
In SQL 2008 its throwing error Incorrect syntax near ' '. IF I remove the space before Where and again give the space its working.
In SQL 2012 this query is showing red sign also before Where that problem is in this space.
I want to know what can be reason that earlier space is not working?
select * from Test.dbo.Test_Spoc where spocNo = '54986'
Add single quotes, I think this might be the issue; you check the code

When trying to delete data in SQL receive following error. XML parsing: line 1, character 39, unable to switch the encoding

Trying to remove certain data from a table, and when I run the following delete statement I get the error below.
delete from table
where type in (2)
Error
Msg 9402, Level 16, State 1, Line 1
XML parsing: line 1, character 39, unable to switch the encoding
If you use names like table and type as table names and column names you should write them in brackets like:
delete from [table] where [type] in (2)

Max NVARCHAR length

I am waiting a stored procedure that creates a script more than 4000 characters in SQL Server 2000. I am using NVARCHAR (4000) but when I use NVARCHAR (MAX) I am getting this error.
What type can I use for this …. ?
Msg 170, Level 15, State 1, Procedure sp_Sxxxx, Line 19
Line 19: Incorrect syntax near 'MAX'.
Msg 137, Level 15, State 1, Procedure sp_ Sxxxx, Line 109
Must declare the variable '#ExecuteScript'.
Msg 137, Level 15, State 2, Procedure sp_ Sxxxx, Line 113
Must declare the variable '#ExecuteScript'.
The MAX keyword is new to SQL Server 2005 and above which is why you are receiving the syntax error. Since you are using SQL Server 2000 you will want to use text, ntext or image data types. Have a look at the docs:
http://msdn.microsoft.com/en-us/library/aa174534(v=sql.80).aspx

SQL Server Truncation Error when column length should be sufficient

I have a table in SQL Server 2008
Table Name : tbl_device
Table Structure:
Column | Type
col1 | nvarchar(200)
Now when i try to insert data into this (it works for shorter cases but) and the string data is long i.e. with
LEN function it is 162
Still the server gives error :
Msg 8152, Level 16, State 4, Line 1
String or binary data would be truncated.
what should be the reason for it ??
There are trailing blanks in the string that generates the error message but they are not counted using len() function.