Need help with eliminating quotations from my columns when running a query

  • Hi Sorry if this is posted in the wrong place.

    I'm using SQL 2012 express.. and just recently learned how to code.

    I wrote a query and keep receiving this error...

    Error converting data type varchar to float.

    here's the query code

    SELECT SUM(cast(lc as float))

    FROM [dbo].[LaborCosts]

    WHERE ppty = 'ga'

    AND PL = 'allctd ktchn expns'

    AND ACCT like 'payroll%'

    I am trying to sum up the values in column LC, and realized I have unnecessary quotations marks. How can I eliminate the quotations from the column, and only query the numerical values?

  • You can use the REPLACE function.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • I would also suggest you build your databases such that the columns that are meant to be numbers are stored as numbers, not strings.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply