# SQL help   need to convert char to real or double

**URL:** <https://boards.straightdope.com/t/sql-help-need-to-convert-char-to-real-or-double/321266>\
**Category:** Factual Questions\
**Created:** [September 12, 2005, 4:57pm UTC](https://boards.straightdope.com/t/sql-help-need-to-convert-char-to-real-or-double/321266 "2005-09-12T16:57:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [September 12, 2005, 4:57pm UTC](https://boards.straightdope.com/t/sql-help-need-to-convert-char-to-real-or-double/321266/1 "2005-09-12T16:57:59Z")

</div>

I have a field of type char which contains real numbers only. I need to convert it so I can do a sum on it.

That is all.

---

<div class="post-metadata">

**Author:** ![Oy](https://avatars.discourse-cdn.com/v4/letter/o/bc8723/32.png) [@Oy](https://boards.straightdope.com/u/Oy)\
**Post date:** [September 12, 2005, 5:01pm UTC](https://boards.straightdope.com/t/sql-help-need-to-convert-char-to-real-or-double/321266/2 "2005-09-12T17:01:21Z")

</div>

What flavor of SQL? Oracle has TO\_NUMBER(in\_str) as a function, but it will die a terrible death if there are any non-numeric characters anywhere.

Can’t speak as to other DBs.

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [September 12, 2005, 5:09pm UTC](https://boards.straightdope.com/t/sql-help-need-to-convert-char-to-real-or-double/321266/3 "2005-09-12T17:09:42Z")

</div>

Tried that. I’m using the sql that comes in ‘microsoft enterprise manager’

---

<div class="post-metadata">

**Author:** ![Walkabout](https://avatars.discourse-cdn.com/v4/letter/w/46a35a/32.png) [@Walkabout](https://boards.straightdope.com/u/Walkabout)\
**Post date:** [September 12, 2005, 5:18pm UTC](https://boards.straightdope.com/t/sql-help-need-to-convert-char-to-real-or-double/321266/4 "2005-09-12T17:18:15Z")

</div>

Microsoft SQL Server should do an implicit conversion, so you should be able to just add them and get a sum. If not use CAST or CONVERT function, such as CAST(char\_var AS number).

For that matter, Oracle does implicit conversion, too.

For more help, find the “Books Online” button on the Start menu in the “Microsoft SQL Server” group.

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [September 12, 2005, 5:30pm UTC](https://boards.straightdope.com/t/sql-help-need-to-convert-char-to-real-or-double/321266/5 "2005-09-12T17:30:43Z")

</div>

The CAST function worked (with type ‘real’ though) Thanks for the help.

---

<div class="post-metadata">

**Author:** ![chrisk](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@chrisk](https://boards.straightdope.com/u/chrisk)\
**Post date:** [September 12, 2005, 6:16pm UTC](https://boards.straightdope.com/t/sql-help-need-to-convert-char-to-real-or-double/321266/6 "2005-09-12T18:16:34Z")

</div>

darn, too slow ☹
