Queries

  • Hey guys , just having a bit of trouble writing this querie.

    i need to create a querie that allows me to select admission charges for a specified type of property during a pacific week.

    I have a table which is dedicated to this called Profit_records , i need to find out the total admission charges for the type_property 'CASTLE' and also list the property_name.

    I was wondering if there was also an add function to get a total sum of the 3 week_1 records for the type CASTLE.

    I'll upload a print of the proft_table.

    thanks for your time , if you can understand that , it took me a while to get it out of my head haha.

  • I think this is what you want

    Select Property_Name, Sum(week_1 + week_2 + week_3 + week_4)

    from Profit_Records

    where Type_Property = 'CASTLE'

    Group by Property_Name

  • Ahh you absolute star , i get this when i execute

    Msg 8117, Level 16, State 1, Line 1

    Operand data type nvarchar is invalid for sum operator.

    what do you suggest i change the data type to ? Thanks for your time

  • try casting the weeks to integers

    Select Property_Name, Sum(cast(week_1 as int) + cast(week_2 as int) + cast(week_3 as int) + cast(week_4 as int))

    from Profit_Records

    where Type_Property = 'CASTLE'

    Group by Property_Name

  • I get this when i execute that code

    Msg 245, Level 16, State 1, Line 1

    Conversion failed when converting the nvarchar value '£307' to data type int.

    should i change the data types in each week on my model?

  • steveb (8/13/2008)


    try casting the weeks to integers

    Select Property_Name, Sum(cast(week_1 as int) + cast(week_2 as int) + cast(week_3 as int) + cast(week_4 as int))

    from Profit_Records

    where Type_Property = 'CASTLE'

    Group by Property_Name

    Ok so , i deleted the pound signs in the colums and the query worked perfectly , anyway around giving the total with the pound sign? and also putting the type_property in the end result also.

    Thanks for yout time , san

Viewing 6 posts - 1 through 5 (of 5 total)

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