Discussion:
Converting varbinary to float array
(too old to reply)
Cathy
2009-10-07 09:09:22 UTC
Permalink
In SQL Server 2005, I have a varbinary(4000) column which contains a
60 element float array. Using SQL (or similar) how can I extract the
contents of the varbinary and print out the data as 60 floats? Each
float has a precision of 9 decimal places.

Many thanks,

cathy
Rahul
2009-10-07 10:10:57 UTC
Permalink
Post by Cathy
In SQL Server 2005, I have a varbinary(4000) column which contains a
60 element float array. Using SQL (or similar) how can I extract the
contents of the varbinary and print out the data as 60 floats? Each
float has a precision of 9 decimal places.
Many thanks,
cathy
Hi,
Please send the DDL and sample data.

Rahul
Rahul
2009-10-07 10:11:08 UTC
Permalink
Post by Cathy
In SQL Server 2005, I have a varbinary(4000) column which contains a
60 element float array. Using SQL (or similar) how can I extract the
contents of the varbinary and print out the data as 60 floats? Each
float has a precision of 9 decimal places.
Many thanks,
cathy
Hi,
Please send the DDL and sample data.

Rahul
Cathy
2009-10-07 10:42:52 UTC
Permalink
Sorry, short of sending you a database backup, I can't do that

Cathy
Gert-Jan Strik
2009-10-07 18:40:19 UTC
Permalink
Cathy,

You would need a better specification of the data format. That is why
Rahul asked for DDL and sample data. You could use SUBSTRING to extract
individual floats, CAST them to float and do with them as you please.
Depending on the data format, you have to create a cursor or loop, or
you might be able to use a set based approach using a numbers table.
--
Gert-Jan
SQL Server MVP
Post by Cathy
In SQL Server 2005, I have a varbinary(4000) column which contains a
60 element float array. Using SQL (or similar) how can I extract the
contents of the varbinary and print out the data as 60 floats? Each
float has a precision of 9 decimal places.
Many thanks,
cathy
Erland Sommarskog
2009-10-07 22:06:31 UTC
Permalink
Post by Cathy
In SQL Server 2005, I have a varbinary(4000) column which contains a
60 element float array. Using SQL (or similar) how can I extract the
contents of the varbinary and print out the data as 60 floats? Each
float has a precision of 9 decimal places.
First you need a Numbers table:
http://www.sommarskog.se/arrays-in-sql-2005.html#tblnum

Then look at the fixed-length method in the same article:
http://www.sommarskog.se/arrays-in-sql-2005.html#fixed-length

And finally:
http://www.sommarskog.se/arrays-in-sql-2005.html#tablelists

This should get you going.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
t***@gmail.com
2013-03-22 23:41:49 UTC
Permalink
Post by Cathy
In SQL Server 2005, I have a varbinary(4000) column which contains a
60 element float array. Using SQL (or similar) how can I extract the
contents of the varbinary and print out the data as 60 floats? Each
float has a precision of 9 decimal places.
Many thanks,
cathy
Though the topic is 4 years old, just in case anyone stumbles upon it. Here's the solution for converting varbinary value to float in T-SQL. It can be applied to arrays also with some modifications.
http://multikoder.blogspot.com/2013/03/converting-varbinary-to-float-in-t-sql.html
Loading...