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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help with Binary conversion

Author  Topic 

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2009-03-10 : 12:56:53
I am having issues getting binary data to display using convert in the below select statement. 'co.company_id' is a binary field. When the below query is run, I get empty results for that column. I am converting because the result set is being exported to a csv via a BCP. If I do not convert, the company_id data is corrupt.

SELECT 'coName', 'coId', 'coSym', 'coHomeSym', 'coHomeBranch', 'coType', 'coStatus', 'todayDate'
UNION ALL
SELECT rtrim(co.company_name) coName, convert(char(8), co.company_id) as coId, rtrim(co.mib_symbol) coSym, rtrim(co.home_office_symbol) coHomeSym, rtrim(co.home_office_branch) coHomeBranch,
rtrim(co.company_type) coType, rtrim(co.status) coStatus, rtrim(getdate()) as todaysDate
from product_service_bridge psb
inner join product p on p.product_id = psb.product_id
left outer join company co on co.company_id = psb.company_id

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-03-10 : 13:10:08
try this function:

select sys.fn_varbintohexsubstring(1,0x01020304,1,8)
select sys.fn_varbintohexsubstring(0,0x01020304,1,8)

output:
0x01020304
01020304

Be One with the Optimizer
TG
Go to Top of Page

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2009-03-10 : 13:22:37
Sweet, worked out great!

Thanks
Go to Top of Page
   

- Advertisement -