SQL Server即席查询将整数列表转换为varchar

时间:2018-08-09 03:32:25

标签: java sql-server

我正在这样使用AdHoc查询

SELECT MemberName 
FROM Member 
WHERE MemberNo IN (:memberNumberList)

但是,MemberNo是varchar列,:memNumberList是nvarchar值的列表。当我使用单个值时,我会像这样将整数变量转换为varchar。

SELECT MemberName
FROM Member
WHERE MemberNo = CONVERT(VARCHAR(10), :memberNumber)

如果我不转换变量,则会发生隐式转换。所以我想将:memNumberList转换为varchar。

有什么主意吗?

这里是Java代码

MapSqlParameterSource param = new MapSqlParameterSource();         param.addValue(“ memberNumberList”,memberNumberList);

    try {
        List<MemberInfo> list = jdbcTemplate.query(
                " SELECT MemberName " +
                        " FROM Member " +
                        " WHERE MemberNo IN (:memberNumberList) ",
                param, new BeanPropertyRowMapper<>(MemberInfo.class));

        return list.stream().collect(Collectors.toMap(MemberInfo::getMemberNumber, Function.identity()));
    } catch (DataAccessException e) {
        throw new MemberException(“There is an issue to search member (+" + e.getMessage() + ")", e);
    }

0 个答案:

没有答案