Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 HELP INSERT 4/3

Author  Topic 

egemen_ates
Yak Posting Veteran

76 Posts

Posted - 2011-12-27 : 03:10:40


HOW CAN i insert data such as 22/7 into sql server tables.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-27 : 03:24:16
whats the datatype you want to store it in? if its numeric it will only store it in decimal form (ie 3.14..)
if varchar you can pass it as '22/7' but if you're doing some manipulations with it then better to store as numeric itself.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

egemen_ates
Yak Posting Veteran

76 Posts

Posted - 2011-12-27 : 03:43:55
I STORE '22/7' BUT HOW CAN I USE,

FOR EX:

I STORE '22/7' SUCH AS VARCHAR,

LATER
(22/7)*44 HOW CAN I USE THIS FORMAT.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-27 : 03:46:20
if you stored it as varchar, you will not be able to use it for computation.

Can you store the result of 22 / 7 instead ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

egemen_ates
Yak Posting Veteran

76 Posts

Posted - 2011-12-27 : 03:56:44
I EXPLAIN WHAT DO I WANT DO VIA EXAMPLE;

FOR EXAPLE;

700*22/7=2200 BUT 700*3.14=2199.999999
MY PROBLEM IS THIS.
Go to Top of Page

egemen_ates
Yak Posting Veteran

76 Posts

Posted - 2011-12-27 : 03:58:58


I EXPLAIN WHAT DO I WANT DO VIA EXAMPLE;

FOR EXAPLE;

700*22/7=2200 BUT 700*3.14=2199.999999
MY PROBLEM IS THIS









quote:
Originally posted by visakh16

whats the datatype you want to store it in? if its numeric it will only store it in decimal form (ie 3.14..)
if varchar you can pass it as '22/7' but if you're doing some manipulations with it then better to store as numeric itself.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

egemen_ates
Yak Posting Veteran

76 Posts

Posted - 2011-12-27 : 03:59:20


I EXPLAIN WHAT DO I WANT DO VIA EXAMPLE;

FOR EXAPLE;

700*22/7=2200 BUT 700*3.14=2199.999999
MY PROBLEM IS THIS


quote:
Originally posted by khtan

if you stored it as varchar, you will not be able to use it for computation.

Can you store the result of 22 / 7 instead ?


KH
[spoiler]Time is always against us[/spoiler]



Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-27 : 04:01:27
what is the required precision of the calculation result ? 2 decimal places ? round( <result>, 2) it



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

egemen_ates
Yak Posting Veteran

76 Posts

Posted - 2011-12-27 : 04:08:43
YOU SAY THIS;

SELECT ROUND((700*3.14),2)

THIS RESULT IS NOT VALID FOR ME,

MAYBE CAN YOU SAY OTHER WAY,
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-27 : 04:10:40
[code]
declare @f float

select @f = 22/7.0

select round(@f * 70, 2)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

egemen_ates
Yak Posting Veteran

76 Posts

Posted - 2011-12-27 : 04:12:04
SELECT (22/7)*700
IS THIS POSSIBLE?
Go to Top of Page

egemen_ates
Yak Posting Veteran

76 Posts

Posted - 2011-12-27 : 04:14:47
TAHNK YOU THIS WORKING

BUT
HOW CAN I INSERT 22/7 OR 10/7 INSERT TABLE
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-27 : 04:19:23
use float data type


insert into yourtable ( float_col)
select 22.0 / 7


you need to ensure the value you specify is in decimal else you will get 22/ 7 as 3 and not 3.14xxxxxx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-27 : 04:53:54
quote:
Originally posted by egemen_ates

TAHNK YOU THIS WORKING

BUT
HOW CAN I INSERT 22/7 OR 10/7 INSERT TABLE


can you turn off caps key while you post? looks really irritating

i didnt understand why you need to see your values as fractions. whats the problem in storing them as decimal with your needed precision and scale limits?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -