Data type between varchar and text

I have a table that currently has a text field I am trying to switch it to a different datatype, like varchar(8000). This worked great for most of my databases, unfortunately there are 4 out of 20 that seem to have more data than 8000 characters in that field so changing to varchar(8000) would truncate the data.

Is there a data type I can use that is NOT text and is more than 8000 characters?  I think 16000 would do, but varchar won't' support that many characters.

I won't get into why I don't want to use text, just gives me way too many issues.
LVL 1
AleksAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lcohanDatabase AnalystCommented:
VARCHAR(MAX) in SQL 2008 is the datatype matching "text and NVARCHAR(MAX) "Ntext"
AleksAuthor Commented:
I have had the same issue with that data type. When I display the information on my ASP page nothing will show. So ... that may not work unfortunately. Ill try again but I remember clearly it was the same issue as text.
AleksAuthor Commented:
I tried and I DID remember correctly, data is not displayed in my ASP page when using the above type.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

lcohanDatabase AnalystCommented:
If you're using SQL Server 2005 or later, use varchar(MAX). The text datatype is deprecated and should not be used for new development work - from SQL BOL below:
https://msdn.microsoft.com/en-us/library/ms187993.aspx

<<
ntext , text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.
>>

And yes, this means APP code may need changes/re-write to accommodate new SQL data type(s)
Anthony PerkinsCommented:
>>I tried and I DID remember correctly, data is not displayed in my ASP page when using the above type.<<
That is an ADO problem and nothing to do with SQL Server.  If you want to post your code (I am going to guess SELECT *)  and we can help you code it correctly in ASP.
AleksAuthor Commented:
It actually does not have Select *

This is the query being run:

SELECT  a.COMID ,         a.CaseID ,         a.Visible ,         a.VisibleEmployer ,         a.Comments ,         a.Updatedby ,         a.Lastupdate ,         a.CommBy ,         a.SectionCase ,         b.MaidenNm ,         b.MailStr ,         a.Importance FROM    dbo.Casecomments a         LEFT JOIN Users AS b ON a.Updatedby = b.UserId WHERE  bla bla bla;" 

Open in new window

AleksAuthor Commented:
I create the recordset using DWCS6.  The code is below.
When I used to have DW8 I was able to move the cursor to the client and then it would display the data from a text field. But CS6 doesn't have an option to change the cursor to client.

<%
Dim rs_notes__MMColParam
rs_notes__MMColParam = "0"
If (Request.Querystring("NewUserID") <> "") Then 
  rs_notes__MMColParam = Request.Querystring("NewUserID")
End If
%>
<%
Dim rs_notes__MMColParam2
rs_notes__MMColParam2 = "0"
If (Session("firmid") <> "") Then 
  rs_notes__MMColParam2 = Session("firmid")
End If
%>
<%
Dim rs_notes
Dim rs_notes_cmd
Dim rs_notes_numRows

Set rs_notes_cmd = Server.CreateObject ("ADODB.Command")
rs_notes_cmd.ActiveConnection = MM_bluedot_STRING
rs_notes_cmd.CommandText = "SELECT  a.COMID ,         a.CaseID ,         a.Visible ,         a.VisibleEmployer ,         a.Comments ,         a.Updatedby ,         a.Lastupdate ,         a.CommBy ,         a.SectionCase ,         b.MaidenNm ,         b.MailStr ,         a.Importance FROM    dbo.Casecomments a         LEFT JOIN Users AS b ON a.Updatedby = b.UserId WHERE   CaseID = ?         AND a.SectionCase = 'Alien'         AND a.FirmId = ? ORDER BY a.Lastupdate DESC;" 
rs_notes_cmd.Prepared = true
rs_notes_cmd.Parameters.Append rs_notes_cmd.CreateParameter("param1", 5, 1, -1, rs_notes__MMColParam) ' adDouble
rs_notes_cmd.Parameters.Append rs_notes_cmd.CreateParameter("param2", 5, 1, -1, rs_notes__MMColParam2) ' adDouble

Set rs_notes = rs_notes_cmd.Execute
rs_notes_numRows = 0
%>

Open in new window

AleksAuthor Commented:
Is there anything between varchar(8000) and varchar(MAX) ?    this change would be easier than going over all the pages in the system that don't display a text field. Plus 90% of the times the entry is way smaller of 8000 characters and in our upgrade we limited the entry to 8000.  Only a few entries have about 10,000 characters and the conversion fails due to data being truncated. A field about 10 or 15000 characters should suffice.
Anthony PerkinsCommented:
It actually does not have Select *
Excellent!  Make sure all your BLOB's (varchar(max), text, etc) are at the end of your SELECT statement and it should be fine.  So for example if Comments is your only BLOB then re-write the query like this:
SELECT  a.COMID,
        a.CaseID,
        a.Visible,
        a.VisibleEmployer,
        a.Updatedby,
        a.Lastupdate,
        a.CommBy,
        a.SectionCase,
        b.MaidenNm,
        b.MailStr,
        a.Importance,
        a.Comments
FROM    dbo.Casecomments a
        LEFT JOIN Users AS b ON a.Updatedby = b.UserId;

Open in new window


Is there anything between varchar(8000) and varchar(MAX) ?  
Nope.
AleksAuthor Commented:
Will that work if there is more than one text field or will one of them have the issue ?
Anthony PerkinsCommented:
Will that work if there is more than one text field or will one of them have the issue ?
Just place them all at the end.  If you are not sure what I mean by that, post the schema for both tables and I will re-write the query.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
Ill give it a try . If it works Ill award the points tomorrow. Thanks !
AleksAuthor Commented:
I changed it to varchar(MAX) and changed the query to have the field at the end .. turns out it works, so Ill try that and see how it goes. Thanks !   If anything else comes up Ill open another ticket.
Luis ElliottCommented:
Text is a BLOB or Binary Large Object data type. It stores data, generally, not in the table, but rather in a space out on the file system. As such, it behaves totally differently than the other string data types CHAR, VARCHAR, NVARCHAR, NCHAR.
Anthony PerkinsCommented:
Text is a BLOB or Binary Large Object data type. It stores data, generally, not in the table, but rather in a space out on the file system.
No.  SQL Server's BLOB data types such as (n)varchar(MAX), varbinary(MAX) and Xml and the deprecated (n)text and image are not stored "in a space out on the file system"  I have no idea where you got this idea (unless you also consider the standard data types to also be stored "in a space out on the file system" simply because they are stored in data files).  The data for BLOB data types are stored in the database and by default in a special BLOB structure.  You may alternatively store the values in row using the "large value types out of row" option.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.