开发者

Save a float value into a char(15) variable in sql server

How can I save the value of float variable NumFiscalActual into the char(15) column impfisfac

On sql server...

UPDATE FACTURA SET
impfisfac= cast(@NumFiscalActual AS varchar)

I know I've to use char variable='char value', but with this cast f开发者_JAVA技巧unction... I dunno =/

Thx in advance


Warning: float is upto 15 significant figures. For very small and very large number, varchar(15) will lose data.

  • 0.0000123456789012345 is >15 length
  • 1.23456789012345E-05 is >15 length

You could try this

UPDATE FACTURA SET impfisfac= cast(@NumFiscalActual AS varchar(15)) WHERE...

(You need the WHERE clause otherwise every row will get the value)

However, there are issues converting floats: you may find that decimal places are lost (I can't remember exact rules).

So, you can use STR, for example

UPDATE FACTURA SET impfisfac= RTRIM(LTRIM(STR(@NumFiscalActual,38,16))) WHERE...

But you'll lose data as above. So why? Or use decimal fixed point types....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜