Reputation: 384
I am a rookie in the SQL world.
Anyway - I am trying to sum a column that is currently stored as a Nvarchar. I have done some research and it ended up that my query looked something like this:
SELECT SUM(CAST(Nvarchar_Col AS INTEGER)
FROM Datatable
I have no idea why but I keep getting the error: Incorrect syntax near the keyword 'FROM'
Any help would be greatly appreciated.
Upvotes: 1
Views: 3728
Reputation: 25152
You can't CAST
#.# to INT from VARCHAR
You need to do the following:
SELECT SUM(ISNULL(CAST(Nvarchar_Col AS DECIMAL(6,2)),0)) as Total
This will fix both errors you are getting.
NOTE: I used 6 precision 2 (####.##) for your decimal but you can change this to whatever you need.
Upvotes: 2