Abha Agrawal
asked on
conversion of varbinary to varchar givig unexpected result
I have a table having varbinary column which is primary key.
Whle trying to retrieve the data as below gives 0 result:
Select count(*) from Trn_Account where cast(TransID as varchar(20)) = '3038D'
below query gives me 1 result:
Select * from Trn_Account where TransID= cast('3038D' as varbinary(20))
Below is my table structure:
Trn_Account:
TransID varbinary no 20 no no no NULL
TDate datetime no 8 no (n/a) (n/a) NULL
TrnsNo numeric no 9 18 0 no (n/a) (n/a) NULL
Please help.
Whle trying to retrieve the data as below gives 0 result:
Select count(*) from Trn_Account where cast(TransID as varchar(20)) = '3038D'
below query gives me 1 result:
Select * from Trn_Account where TransID= cast('3038D' as varbinary(20))
Below is my table structure:
Trn_Account:
TransID varbinary no 20 no no no NULL
TDate datetime no 8 no (n/a) (n/a) NULL
TrnsNo numeric no 9 18 0 no (n/a) (n/a) NULL
Please help.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Select count(*) from Trn_Account where CONVERT(varchar(20), TransID , 2)= '3038D'