• No. Cast/convert will not help here. You need to remove SUM() around database_name.

    Evenafter that the query fails.

    What are you trying to achieve? Other may help you to rewrite the query.