Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server/DTS: text field to char field

Posted on 2008-10-22
2
Medium Priority
?
342 Views
Last Modified: 2013-11-30
I'm accessing an existing SQL 2005 table that has a TEXT field with length of 2147483647. The data in the field is character-delimited.  (If I want to find the Date of Service, I'd have to look for "DATEOFSERVICE" and date would appear shortly after that.)

Is there a way to do this?  

Does the TEXT field need to be convert to char?  If so, how?

Thanks, Ashley
0
Comment
Question by:BCAshleyP
2 Comments
 
LVL 25

Accepted Solution

by:
DBAduck - Ben Miller earned 1500 total points
ID: 22780716
Text fields cannot be manipulated like a varchar field.  So you would have to convert it to varchar(4000) or whatever length is long enough.
In SQL 2005 you should use varchar(max) instead of text because then you can just do a charindex() instead of conversion and charindex().

CONVERT(varchar(4000), textfield1)

Does that help?
0
 

Author Comment

by:BCAshleyP
ID: 22781673
Thanks!  For some reason I couldn't get it to work (operator error I'm sure), but this led me to the obvious: I copied the data into a new table (I don't own the original table), but defined the text field X as varchar(max) in the new table.  This seems to work.

THANKS again for your help!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

885 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