在sql server中添加+'%'时遇到问题 - 获取错误消息“将数据类型varchar转换为数字时出错”

时间:2017-02-22 18:53:47

标签: sql-server

这是我的查询行,我收到错误信息8114,级别16,状态5.我有完全按照我需要的总和和舍入 - 只是无法使+'%'部分工作:< / p>

SUM(CAST(ROUND(ENROLLMENT,1) AS DECIMAL (10,2)))/SUM(CAST(ROUND(CAPACITY,1) AS DECIMAL (10,2))) *100 + '%' AS 'fill rate %'

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

将您的小数转换为varchar

findPreference(getString(R.string.notification_key)).setOnPreferenceChangeListener(this);

@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {

    if (preference.getKey().equals(getString(R.string.notification_key))) {

        Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), Uri.parse(newVal.toString()));
        String name = ringtone.getTitle(getActivity());
        preference.setSummary(name);
    }

    return false;
}

 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode,resultCode,data);
    }

或者根本不添加%。列标题已经说明了它是一个%字段...

cast(SUM(CAST(ROUND(ENROLLMENT,1) AS DECIMAL (10,2)))/SUM(CAST(ROUND(CAPACITY,1) AS DECIMAL (10,2))) *100 as varchar(100)) + '%' AS 'fill rate %'

或者,如果您要显示此内容,则显示屏会在显示小数值的字段右侧添加“&#39;%&#39;”