Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I was wandering how should the case statement go;Main TableTitle Daysabcde 3mtSeperate TableTitle Priceabcde 3.99Another TableTitle acresabcde 350 Scenerio is that i want to calculate an overall pricewith Days * Price * AcresBut the problem is that Days has "3mt"How do I accomplish this Task:Example script is as FollowsSelect (MainTable.Days * SeperateTable.Price * AnotherTable.acres)AS OverallPriceFrom MainTableINNER JOIN SeperateTable.Title = MainTable.Title)INNER JOIN AnotherTable.Title = MainTable.Title)Result::Error converting data type varchar to numeric.Thanks for the help in AdvanceDanny Dubroc
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2007-01-19 : 15:56:40
That's not the only error. You have a lot of paranthesis too.
Select CAST(MainTable.Days AS NUMERIC(12, 8)) * CAST(SeperateTable.Price AS NUMERIC(12, 8)) * CAST(AnotherTable.acres AS NUMERIC(12, 8))AS OverallPriceFrom MainTableINNER JOIN SeperateTable.Title = MainTable.TitleINNER JOIN AnotherTable.Title = MainTable.Title
Peter LarssonHelsingborg, Sweden
Danny4003
Starting Member
40 Posts
Posted - 2007-01-19 : 16:12:11
it throws me the same error about converting data type varchar to numeric do you think that maybe i have to castDanny Dubroc
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2007-01-19 : 16:24:31
Of course! What does 3mt mean? 3 months? 92 days?
Select CAST(replace(MainTable.Days, 'mt', '') AS NUMERIC(12, 8)) * CAST(SeperateTable.Price AS NUMERIC(12, 8)) * CAST(AnotherTable.acres AS NUMERIC(12, 8))AS OverallPriceFrom MainTableINNER JOIN SeperateTable.Title = MainTable.TitleINNER JOIN AnotherTable.Title = MainTable.Title