我正在尝试从SQL命令中检索List。我正在做这个
当我使用硬编码参数运行查询时,我得到2列(B1BRNB,PREMIUM),但我无法使用波纹管代码获取它们。我会感激任何帮助!
public class Premiums
{
public int B1BRNB { get; set; }
public double PREMIUM { get; set; }
public List<string> GetPremiums(string policyId)
{
var policy = _quoteRepository.GetPolicy(policyId);
string sql = "SELECT B1BRNB, SUM(SARPREM) AS PREMIUM " +
" FROM PMSPSA15BR JOIN (SELECT DISTINCT(B1J4TX),B1BRNB " +
" FROM ASB1CPPBR WHERE B1ASTX = '@PolicyId' AND B1ADNB = '@Module' ) a " +
" ON (B1J4TX = SARUNIT) " +
" WHERE POLICY0NUM = '@PolicyId' AND MODULE = '@Module' "+
" GROUP BY B1BRNB " +
" ORDER BY B1BRNB";
var match = _dataContext.ExecuteSql<Premiums>(
sql,
new DB2Parameter("@PolicyId", policy.Id),
new DB2Parameter("@Module", policy.Line.Module)).ToList();
return match;
}
答案 0 :(得分:1)
在这里
"WHERE B1ASTX = '@PolicyId' AND B1ADNB = '@Module' ) a"
. . . . . . .
"WHERE POLICY0NUM = '@PolicyId' AND MODULE = '@Module' "
删除单引号
"WHERE B1ASTX = @PolicyId AND B1ADNB = @Module ) a"
. . . . . . .
"WHERE POLICY0NUM = @PolicyId AND MODULE = @Module "
使用参数时,不要用引号括起它们,因为它们被视为字符串值