Solved

Data getting truncated while saving data in table of text datatype.

Posted on 2002-04-11
6
688 Views
Last Modified: 2011-10-03
Hi All

I am having table with column description of text datatype.When i save the character data using insert statement of length 20000 it gets truncated to only 5000 charaters in the table.

In the table definition it shows datatype text and length 16
awaiting your replies.

shamshularphin.



0
Comment
Question by:arphin
6 Comments
 
LVL 2

Accepted Solution

by:
skhorshid earned 25 total points
ID: 6933466
I would not use text or ntext unless it was completely nessicary.

Howver if you need 20000 chars in one field then you will need to use a stored procedure to insert the text.

create procedure inserttext(@input text) as
insert into mytable(textcol) values(@input)

If you are using ADO and VB you would execute your procedure like this

Then you will need to use a command object to pass the text value byref.

'this inserts 9000 long character string

Dim cn As New ADODB.Connection
Dim p As New ADODB.Parameter
Dim cmd As New ADODB.Command
Dim str As String * 9000
cn.Open "DSN=yourdsn or connect string"
cmd.ActiveConnection = cn
str = "1fvbrsghb"
Set p = cmd.CreateParameter("tt", adLongVarChar, adParamInput, 9000, str)
cmd.CommandText = "iinsert"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Append p
cmd.Execute






0
 
LVL 2

Expert Comment

by:skhorshid
ID: 6933471

These two lines should read..

Set p = cmd.CreateParameter("input", adLongVarChar, adParamInput, 9000, str)
cmd.CommandText = "inserttext"
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 25 total points
ID: 6933489
look at this q:

http://www.experts-exchange.com/mssql/Q.20286017.html

or read this "solution":
CREATE PROCEDURE UpdateJobResult
@JobID Int,
@StatusID TinyInt,
@JobResult Text
As

DECLARE @ptrval binary(16)
DECLARE @offset int

UPDATE Jobs
Set LastUpdatedTime = GetDate(),
 StatusID= @StatusID,
 ResultSize = DataLength(@JobResult) + ResultSize
Where JobID= @JobID

update Jobs
set JobResult = '' where
JobID = @JobID and JobResult is null

SELECT @ptrval = TEXTPTR(JobResult),
     @offset = DATALENGTH(JobResult)
FROM Jobs
WHERE JobID= @JobID


UPDATETEXT [Jobs].[JobResult] @ptrval @offset NULL @JobResult
GO


CHeers
0
 
LVL 8

Expert Comment

by:chigrik
ID: 6938554
You can insert a text value of length 20000 by using insert statement.
Maybe you should use SET TEXTSIZE statement to specify the size of
text and ntext data returned with a SELECT statement.
The default setting is 4Kb.
To see the real size of the particular column you can use DATALENGTH function.


With best regards,
Alexander Chigrik
http://www.MSSQLCity.com/ - all about MS SQL
(SQL Server Articles, FAQ, Scripts, Tips and Test Exams).
0
 

Expert Comment

by:CleanupPing
ID: 9280636
arphin:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Row insertion failed. Array 5 48
SQL Quer 4 23
What is the best way to use power bi and ssrs 3 27
Getting invalid Syntax SQL. 3 21
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

821 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