Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function to convert varchar to char

Status
Not open for further replies.

barasel1

Programmer
Dec 5, 2006
5
US
I have a column named AUDIT_SECTION defined as varchar(600).

I would like to query the table and view the content of this particular column.

In SQL Query analyzer, when I do a select audit_sction from mytable, value of the column shown is not readable.

I assume, there might be column function which would convert the varchar to char.

I had tried the CAST and CONVERT functions. Even them, do not return data in readable format.

Thanks
 
CONVERT will do it.

Code:
declare @sometext varchar(250)

set @sometext = 'this is some text'

select @sometext + '/'
select convert(char (50), @sometext) + '/'code]

I think you have a deeper issue making your column unreadable though.  What is the data type?  And what is the data that you want to read?  Is it simply a matter of not being able to read it because of the column width displayed?

Good Luck,

Alex

Ignorance of certain subjects is a great part of wisdom
 
Thanks.

I will try.
The data is supposed to be character(still not yet validated)

Also, it looks like, i can try substring function to do it.
 
If it is an import you are doing, you might try using a unicode datatype (nchar, nvarchar). There are some characters that won't show up properly in a normal char field.

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top