Solved

Decimal to Binary

Posted on 2012-04-11
3
316 Views
Last Modified: 2012-06-21
I have a SSIS package that I have a field that is a Decimal now but it needs to be converted to a binary string for example.  One of the values is 152  and that should actual after it is converted look like 10011000.  I have had it figured out in an access database by using my own module,  But now we have ported over to SQL and i need  this to be done in SSIS.  Please help.
0
Comment
Question by:Brickwall
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
yawkey13 earned 500 total points
ID: 37835824
CREATE FUNCTION udf_bin_me (@IncomingNumber int)
RETURNS varchar(200)
as
BEGIN
 
      DECLARE @BinNumber      VARCHAR(200)
      SET @BinNumber = ''
 
      WHILE @IncomingNumber <> 0
      BEGIN
            SET @BinNumber = SUBSTRING('0123456789', (@IncomingNumber % 2) + 1, 1) + @BinNumber
            SET @IncomingNumber = @IncomingNumber / 2
      END
 
      RETURN @BinNumber
 
END
0
 
LVL 6

Expert Comment

by:yawkey13
ID: 37835829
I got this function a while ago from the MSDN forums.
0
 

Author Comment

by:Brickwall
ID: 37835896
how o i incorporate this into my SIS package?
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question