Monday 5 March 2012

CONVERT float to nvarchar

Attempting to compare company numbers (e.g. ABN) stored as datatype float to text strings is complicated by the fact that the default display for float numbers over 6 digits is scientific notation. To work around this you need firstly to convert the float to a bigint, then convert to nvarchar.

SELECT CONVERT (nvarchar(14),CONVERT(bigint,t.FloatABN))
FROM Table t

This conversion then allows a join to be made between the text ABN and the float ABN.

SELECT *
FROM Table t
INNER JOIN Table2 t2
ON t.TextABN = CONVERT (nvarchar(14),CONVERT(bigint,t.FloatABN))

No comments:

Post a Comment