Getting 4 characters from a float type
-
8 июня 2012 г. 21:19
Hello;
I've a table that has a column barcode float type.
When i want to get 4 charachters from 4th index, it returns me incuding exponent 'e'
For example;
8699502093393
is should return me '9502' but,
SUBSTRING(CAST(barcode as nvarchar(max)),4,4)
SUBSTRING(CONVERT(NVARCHAR(MAX),barcode),4,4)
both return me 995e
How can i solve this problem?
*I must use barcode in float type
Все ответы
-
8 июня 2012 г. 21:22Модератор
Try
declare @Barcode float set @Barcode = 8699502093393 select @Barcode barcode, substring(ltrim(str(@barcode,20)),4,4) as [Part]
For every expert, there is an equal and opposite expert. - Becker's Law
My blog -
8 июня 2012 г. 21:23
SUBSTRING(CONVERT(NVARCHAR(MAX),CONVERT(DEcimal,BARKOD)),4,4) has solved my problem.- Помечено в качестве ответа emperorIT 8 июня 2012 г. 21:23
-
8 июня 2012 г. 21:24МодераторSee my simpler solution using STR function.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog -
8 июня 2012 г. 21:38Модератор
Float is really the wrong type for barcode.
Use INT or BIGINT.
Demo:
declare @Barcode float, @BarINT BIGINT = 8699502093393333 set @Barcode = 8699502093393333 select @Barcode, @BarINT -- 8.69950209339333E+15 8699502093393333
Kalman Toth SQL SERVER & BI TRAINING
-
8 июня 2012 г. 21:42Модератор
I think it needs to be a character field. We use character for barcodes and UPC.For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Предложено в качестве ответа Hasham NiazEditor 8 июня 2012 г. 21:51
- Помечено в качестве ответа Kalman TothMicrosoft Community Contributor, Moderator 9 июня 2012 г. 3:00

