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 2000 Forums
 SQL Server Development (2000)
 conversion

Author  Topic 

sona
Yak Posting Veteran

68 Posts

Posted - 2001-11-12 : 05:35:52
Is there any function to convert a decimal to binary in sql

eg 2 to 0000010

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2001-12-02 : 06:27:38
I cannot apologise enough for this:

SELECT REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(
SUBSTRING(Master.dbo.fn_varbintohexstr(OrderId),3,8),
'0', 'x'), '1', 'y'), '2', '0010'), '3', '0011'), '4', '0100'),
'5', '0101'), '6', '0110'), '7', '0111'), '8', '1000'), '9', '1001'),
'a', '1010'), 'b', '1011'), 'c', '1100'), 'd', '1101'), 'e', '1110'),
'f', '1111'), 'x', '0000'), 'y', '0001')
FROM Northwind.dbo.Orders

(yes, of course it would make more sense to adapt fn_varbintohexstr)

Edited by - Arnold Fribble on 12/02/2001 06:33:24
Go to Top of Page
   

- Advertisement -