Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing a Table's data type in code.

Posted on 2011-09-25
8
Medium Priority
?
227 Views
Last Modified: 2012-05-12
After I Imported a file from Excel, all the number fields are float.
I know I can change the Mappings when I import, but I don't know if that is going to corrupt the data or not.

Can I update the Table's field types in a stored procedure?
I want to change a few to money and int.
Also some of the fields are like : 54.232312121
How can I make them 2 decimal places like : 54.23 ?  thanks

0
Comment
Question by:MikeMCSD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 36595686
MikeMCSD,

If you are concerned that some of your Excel data will be "messy" (e.g., what's supposed to be a numeric field may contain text every so often), then the safest thing to do would be to load to a staging table first in which ALL of the columns use varchar or nvarchar.  You can then run some validation procedures against the staging data before transferring the data into your permanent tables.

Patrick
0
 
LVL 16

Author Comment

by:MikeMCSD
ID: 36595753
>> safest thing to do would be to load to a staging table first  . .
Using the Import Wizard or something else? Isn't that what I'm doing now?

All the numeric  fields are ok after the import, they are just floats.
I need to update other fields (that have money and int data types) in another Table
from this Imported table that has the floats.
And also, this is going to be a weekly thing I have to run.


0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 36595758
If you have no concerns about whether your data need to be validated, then simply fix your import process to use the specific data types that you want, rather than letting them default to float.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Author Comment

by:MikeMCSD
ID: 36595842
Yeah I guess . . . . but this Import Wizard seems to have a mind of its own sometimes.
I did try that and it did work, but the money fields still displayed 45.15151215115.
Is there a way to fix that with an Update statement?





0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 36595849
Better check that again.  Since the money data type's maximum decimal precision is four places, I doubt that you are actually using that data type if your value is showing as 45.15151215115

:)
0
 
LVL 16

Author Comment

by:MikeMCSD
ID: 36595865
Yes, not like that, but like this : 1.5875
How do I get it to 2 places, rounded up?
0
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 36596038
To always round up:

UPDATE SomeTable
SET SomeColumn = ROUND(SomeColumn + 0.0049, 2)

That will still store 4 decimal places, but the final two will be zeroes.
0
 
LVL 16

Author Closing Comment

by:MikeMCSD
ID: 36597087
thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question