SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


CONVERT varchar (50) to Decimal (4,4), 2012 Server Express


CONVERT varchar (50) to Decimal (4,4), 2012 Server Express

Author
Message
cjamt
cjamt
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 31
Greetings,

I'm about as newbie as they come.

I am using SQL Server Management Studio Express 2012 on a Win7 machine.

BACKGROUND: I have imported data (in sections) to several tables from an excel spreadsheet 30 columns wide and containing 338 records. The only way I was able to do this was copy like data into separate Excel spreadsheets, convert to txt and import to a table.

ISSUE: 2 of the columns contain numeric frequencies but are now varchar (50). The format is 000.000. I would like to convert the data in these columns to decimal (4.4) (just to be safe). Can anyone tell me if this is possible? And, if so, how? If not, is there a better way to import the data to make this possible?

Appreciate your help.

Thanks,

cjamt
ColdCoffee
ColdCoffee
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3659 Visits: 5548
Try NUMERIC(8,4).
cjamt
cjamt
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 31
SSCrazy:

It worked!!!! Imagine that. Thanks. CJAMT:-D
adminorama
adminorama
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 94
The reason why decimal(4,4) doesn't work is because the scale is equal to precision, and that doesn't fit with the number format you have.
http://msdn.microsoft.com/en-us/library/ms187746.aspx
GilaMonster
GilaMonster
SSC Guru
SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)

Group: General Forum Members
Points: 86639 Visits: 45253
Decimal 4, 4 allows for 4 digits, all 4 to the right of the decimal. So it stores values between 0 and 0.9999 (on the positive side), but it cannot store 1.0000 as that requires 5 digits, not 4.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


cjamt
cjamt
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 31
Gail: Thanks for the response.

So, If I were to use decimal for this application to store frequencies in the format of 0000.0000, I would need decimal (8, 4) Correct. Like using Numeric (8,4). For the purposes of frequencies, with a possible need to do addition/subtraction of standard offsets say 6Mhz, which data type should I use? Is there a benefit of one over the other in this application?

Again, Thanks.

cjamt
cjamt
cjamt
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 31
adminorama:

Thanks for the response! I was wondering if there was a preference of decimal over numeric in my situation. Please see my post to Gail.

Thanks again for your response.

CJAMT
GilaMonster
GilaMonster
SSC Guru
SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)

Group: General Forum Members
Points: 86639 Visits: 45253
Numeric and decimal are identical data types.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


cjamt
cjamt
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 31
Gail,

Thanks again. I guess may issue was providing enough room on either side of the decimal that caused the conversion error. Thanks for your patience.

cjamt
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search