Max NVARCHAR length - sql-server-2000

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

Related

Simple conversion of SQL date field to mm/dd/yyy

I'm having a problem converting three columns to mm/dd/yyyy format in MS SQL Server.
There are a number of methods I've looked up here but nothing that quite worked when I tried to implement it. It's a very basic set of columns I'm pulling.
SELECT
[Incident_Number]
,[Corporate_ID]
,[Assignee_Login_ID]
,select *, cast ([Submit_Date] as date) <TIME_CREATED> from SERVICEMGMT where date = 'mm/dd/yyyy'
,[Last_Resolved_Date] as TIME_RESOLVED
,[Closed_Date] as TIME_CLOSED
,[Description]
FROM [SERVICEMGMT].[dbo].[Help_Desk]
Where (corporate_id LIKE ('b%') AND TEMPLATE_NAME = ('PC: Local Build/Deployment') AND STATUS > 3);
I'm getting a basic incorrect syntax error. The actual error messages are:
Msg 156, Level 15, State 1, Line 5 Incorrect syntax near the keyword 'select'.
Msg 102, Level 15, State 1, Line 6 Incorrect syntax near ','.

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

Msg 8115, Level 16, State 2, Line 2 Arithmetic overflow error converting expression to data type int

I am getting an error after firing this query.
select COUNT(*)
from [DB1].dbo.Transaction(nolock) t
join [DB2].dbo.visits (nolock) v
on t.V_ID=v.V_ID
where t.Ct_ID=11
and t.Timestamp>'06-08-2015'
and v.C_ID is null
Error:
Msg 8115, Level 16, State 2, Line 2 Arithmetic overflow error converting expression to data type int
Try using COUNT_BIG instead of COUNT.
Read this article for more information. Additionally, this shows the limits for the different types of INTs.

Bulk Insert Multiple Pipe Data in Table

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.

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.