Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 retrive int values from binary field

Author  Topic 

osmansays
Starting Member

6 Posts

Posted - 2006-06-14 : 04:21:25
I have an Int and varchar values saved in an Image data field and I want to retrive them and make queries upon these values , how can I write a stored procedure to do that ?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-14 : 04:46:47
Why did you store int and varchar data in image column?
Use proper datatype to store data
Post some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-06-14 : 07:46:35
If you must, you can convert it to varbinary and then to varchar. But you should listen to madhivanan's sage advice.

--data
declare @t table (x image)
insert @t
select '1'
union all select '2'
union all select 'A'

--calculation
select cast(cast(x as varbinary) as varchar(10)), x from @t

/*results
x
---------- ------
1 0x31
2 0x32
A 0x41
*/


Ryan Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

osmansays
Starting Member

6 Posts

Posted - 2006-06-14 : 10:12:53
thanks RyanRandall and madhivanan ,
I know , it is strange to save int and varchar in Image field but I have to because I am quering a database table for a product that we bought from a company so it is not my choice to insert values like this in Image field .
I tried the select query statment that RyanRandall wrote in analyzer and it returns an empty field to me ???!!! I still can not get the values and I am sure there is values some are integer values and some are varchar .
Go to Top of Page
   

- Advertisement -