By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

How to divide a value into Two

P: 73
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
Share this Question
Share on Google+
6 Replies


mwasif
Expert 100+
P: 801
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
Expert 5K+
P: 8,127
For this the logic is to consider the number as string not number and findout the posistion of the "."
Feb 11 '08 #3

P: 73
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
Expert 100+
P: 2,367
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
Expert 100+
P: 801
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
Expert 2.5K+
P: 2,878
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.