Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Storing Doubles in SQL

I can successfully read and write from/to sql using excel macros.

I have numbers in my worksheet (currency and large numbers and fractions)
that I so far handle using "double" in my macros.

a) My basic question is what is the best way to store these values in my sql
database. Should I define a "Double" or "Float" field in my database or
should I define a "string" in my sql database.

b) since the sql text sent to the server is all text is it best or
neccessary to convert and format the Double to a String before using in a sql
command ?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Storing Doubles in SQL

No, always use a data type that is equal. You can always use a type that is
greater as well but you're possibly wasting storage space.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"naive14" wrote:
I can successfully read and write from/to sql using excel macros.

I have numbers in my worksheet (currency and large numbers and fractions)
that I so far handle using "double" in my macros.

a) My basic question is what is the best way to store these values in my
sql
database. Should I define a "Double" or "Float" field in my database or
should I define a "string" in my sql database.

b) since the sql text sent to the server is all text is it best or
neccessary to convert and format the Double to a String before using in a
sql
command ?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Storing Doubles in SQL

Thanks. So I'll use a Double definition in my sql database.

As to the second part of the question, should I convert the double to a
string and format as in :

dim s, sqlCMD as string
dim d as double

d = 5459.459
s = Format(d, "##,##0.00")

sqlCMD = "INSERT INTO tablex VALUES ('" & s & "')
' the above probably rounds off to 2 decimals


or is this valid ...

sqlCMD = "INSERT INTO tablex VALUES ('" & d & "')


"Dave Patrick" wrote:

No, always use a data type that is equal. You can always use a type that is
greater as well but you're possibly wasting storage space.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"naive14" wrote:
I can successfully read and write from/to sql using excel macros.

I have numbers in my worksheet (currency and large numbers and fractions)
that I so far handle using "double" in my macros.

a) My basic question is what is the best way to store these values in my
sql
database. Should I define a "Double" or "Float" field in my database or
should I define a "string" in my sql database.

b) since the sql text sent to the server is all text is it best or
neccessary to convert and format the Double to a String before using in a
sql
command ?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Storing Doubles in SQL

You don't want the string delimiters. Do something like;

INSERT INTO Employees
(EmployeeID, FirstName, LastName)
VALUES (9999, N'John', N'Smith')


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"naive14" wrote:
Thanks. So I'll use a Double definition in my sql database.

As to the second part of the question, should I convert the double to a
string and format as in :

dim s, sqlCMD as string
dim d as double

d = 5459.459
s = Format(d, "##,##0.00")

sqlCMD = "INSERT INTO tablex VALUES ('" & s & "')
' the above probably rounds off to 2 decimals


or is this valid ...

sqlCMD = "INSERT INTO tablex VALUES ('" & d & "')

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Storing Doubles in SQL

Should have been;

INSERT INTO Employees
(EmployeeID, FirstName, LastName)
VALUES (" & d & ", N'John', N'Smith')

Also it's pointless to format the value before storing it.


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"naive14" wrote:
Thanks. So I'll use a Double definition in my sql database.

As to the second part of the question, should I convert the double to a
string and format as in :

dim s, sqlCMD as string
dim d as double

d = 5459.459
s = Format(d, "##,##0.00")

sqlCMD = "INSERT INTO tablex VALUES ('" & s & "')
' the above probably rounds off to 2 decimals


or is this valid ...

sqlCMD = "INSERT INTO tablex VALUES ('" & d & "')


"Dave Patrick" wrote:

No, always use a data type that is equal. You can always use a type that
is
greater as well but you're possibly wasting storage space.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"naive14" wrote:
I can successfully read and write from/to sql using excel macros.

I have numbers in my worksheet (currency and large numbers and
fractions)
that I so far handle using "double" in my macros.

a) My basic question is what is the best way to store these values in
my
sql
database. Should I define a "Double" or "Float" field in my database
or
should I define a "string" in my sql database.

b) since the sql text sent to the server is all text is it best or
neccessary to convert and format the Double to a String before using in
a
sql
command ?






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Storing Doubles in SQL

Thanks a lot for the advice Dave.

"Dave Patrick" wrote:

Should have been;

INSERT INTO Employees
(EmployeeID, FirstName, LastName)
VALUES (" & d & ", N'John', N'Smith')

Also it's pointless to format the value before storing it.


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"naive14" wrote:
Thanks. So I'll use a Double definition in my sql database.

As to the second part of the question, should I convert the double to a
string and format as in :

dim s, sqlCMD as string
dim d as double

d = 5459.459
s = Format(d, "##,##0.00")

sqlCMD = "INSERT INTO tablex VALUES ('" & s & "')
' the above probably rounds off to 2 decimals


or is this valid ...

sqlCMD = "INSERT INTO tablex VALUES ('" & d & "')


"Dave Patrick" wrote:

No, always use a data type that is equal. You can always use a type that
is
greater as well but you're possibly wasting storage space.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"naive14" wrote:
I can successfully read and write from/to sql using excel macros.

I have numbers in my worksheet (currency and large numbers and
fractions)
that I so far handle using "double" in my macros.

a) My basic question is what is the best way to store these values in
my
sql
database. Should I define a "Double" or "Float" field in my database
or
should I define a "string" in my sql database.

b) since the sql text sent to the server is all text is it best or
neccessary to convert and format the Double to a String before using in
a
sql
command ?





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Storing Doubles in SQL

You're welcome.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"naive14" wrote:
Thanks a lot for the advice Dave.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i get rid of doubles from my database? Bill Excel Discussion (Misc queries) 2 April 27th 10 07:55 AM
Summarizing doubles Sippan Excel Worksheet Functions 1 June 17th 08 09:05 AM
Sorting doubles rbrunz Excel Discussion (Misc queries) 1 June 13th 08 04:20 PM
How do I set up a Doubles Tennis roster for 12 players? AliJax New Users to Excel 3 September 17th 05 12:31 AM
Comparing Doubles big t Excel Programming 1 September 20th 04 10:16 AM


All times are GMT +1. The time now is 03:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"