try this statemet

sql = "select sum(total) from <table> where code='<value>'"