| Author |
Topic |
|
collie
Constraint Violating Yak Guru
400 Posts |
Posted - 2007-10-01 : 08:31:38
|
| Hi,I have a char field called Actuals that I want to convert to money.select convert(money,Actual ) Actual from FinanceFactTable_tempHowever, i get the following error:Cannot convert a char value to money. The char value has incorrect syntax.How can i convert char to money?ThanksWhisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-01 : 08:35:59
|
Yes, use the CONVERT funtion described in Books Onlineunder CAST & CONVERT. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-01 : 08:40:31
|
Probably you have some data in char column which is not in proper format. Find out non-numeric data using:select * from table where column1 not like '%[^0-9]%' Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
collie
Constraint Violating Yak Guru
400 Posts |
Posted - 2007-10-01 : 09:08:43
|
| Yes, I think you are correct. In the Actual field i have the value (23.67).How can I tell the query that if the number is in brackets () to add a minus to the number and to delete the brackets so that the result will be -23.67?ThanksThis is the structure of my tableUSE [AHT_DW]GO/****** Object: Table [dbo].[FinanceFactTable_temp] Script Date: 10/01/2007 15:00:57 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[FinanceFactTable_temp]( [AccountNumber] [bigint] NOT NULL, [Date] [datetime] NOT NULL, [CompanyCode] [int] NOT NULL, [Actual] [nvarchar](100) COLLATE Hebrew_CI_AS NULL, [Target] [money] NULL) ON [PRIMARY]I only have one row in the table:Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much. |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-01 : 09:13:44
|
| [code]Select '-' + Replace(Replace(Column, '(', ''), ')', '')from TableWhere column like '(%)'[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
collie
Constraint Violating Yak Guru
400 Posts |
Posted - 2007-10-01 : 09:27:19
|
Thanks for the great helpWhisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-01 : 09:42:10
|
To allow for a single decimal point you probably needselect * from table where column1 not like '%[^0-9.]%' OR column1 LIKE '%.%.%' Might also need to allow for leading "+" or "-"Kristen |
 |
|
|
evilDBA
Posting Yak Master
155 Posts |
Posted - 2007-10-01 : 09:56:57
|
| or justwhere ISNUMERIC(yourcolumn)=1 |
 |
|
|
collie
Constraint Violating Yak Guru
400 Posts |
Posted - 2007-10-01 : 09:59:48
|
| I now have the following values in Actual field:-23.67-1.703,086.70-5333,67When I run your query:select * from table where column1 not like '%[^0-9]%'I get only one return value:-1.703,086.70How can I convert the values to money. Money does accept minus as far as I know and also commas and fullstops so why do i still get the same error?ThanksWhisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much. |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-01 : 10:04:54
|
| Because you have two decimal point in -1.703,086.70.See kristen's suggestionHarsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
collie
Constraint Violating Yak Guru
400 Posts |
Posted - 2007-10-01 : 10:11:33
|
| I am sorry but I don't understand Kristen's reply really and I am not sure how it will help me cast from char to money.Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much. |
 |
|
|
Kristen
Test
22859 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-03 : 03:09:18
|
quote: Originally posted by evilDBA or justwhere ISNUMERIC(yourcolumn)=1
Note that Isnumeric() is not reliableselect * from( select '12.234' as data union all select '13d2' as data union all select '$123' as data union all select '12e3' as data ) as twhere isnumeric(data)=1 MadhivananFailing to plan is Planning to fail |
 |
|
|
|