469,946 Members | 1,751 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,946 developers. It's quick & easy.

How to divide a value into Two

Please give appropriate sql query

in a table i have a field Field1 of Numeric datatype
i stored 9.45 in that
how to separate that value (9.45) in two as 9, 45

please send appropriate query
Thank You
Feb 8 '08 #1
6 2434
mwasif
802 Expert 512MB
Here is a simple example to achieve this
Expand|Select|Wrap|Line Numbers
  1. SELECT SUBSTRING_INDEX(Field1, '.', 1), SUBSTRING_INDEX(Field1, '.', -1)
  2. FROM table
Feb 10 '08 #2
debasisdas
8,127 Expert 4TB
For this the logic is to consider the number as string not number and findout the posistion of the "."
Feb 11 '08 #3
Here is a simple example to achieve this
Expand|Select|Wrap|Line Numbers
  1. SELECT SUBSTRING_INDEX(Field1, '.', 1), SUBSTRING_INDEX(Field1, '.', -1)
  2. FROM table
Thanks
i was tried it in sql2005 but it is giving error like 'SUBSTRING_INDEX' is not a recognized function name.
plz give appropriate query in sql2005
Feb 11 '08 #4
amitpatel66
2,367 Expert 2GB
Please give appropriate sql query

in a table i have a field Field1 of Numeric datatype
i stored 9.45 in that
how to separate that value (9.45) in two as 9, 45

please send appropriate query
Thank You
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT REPLACE('9.45','.',',') from table_name;
  3.  
  4.  
Feb 11 '08 #5
mwasif
802 Expert 512MB
Thanks
i was tried it in sql2005 but it is giving error like 'SUBSTRING_INDEX' is not a recognized function name.
plz give appropriate query in sql2005
SUBSTRING_INDEX() is a MySQL function.

Moving the thread to MS SQL Forum.
Feb 11 '08 #6
ck9663
2,878 Expert 2GB
try:

Expand|Select|Wrap|Line Numbers
  1. SELECT REPLACE(cast(Field1 as varchar(20)),'.',',') FROM table_name
  2.  
--ck
Feb 11 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Jack Smith | last post: by
10 posts views Thread by Dan Williams | last post: by
3 posts views Thread by Ryan | last post: by
5 posts views Thread by per.nordlow | last post: by
8 posts views Thread by =?Utf-8?B?bWljaGFlbGd3ZWllcg==?= | last post: by
27 posts views Thread by jty0734 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.