Len函数对join子句

时间:2012-11-19 15:34:38

标签: sql-server

Join db_abc
On a.userid = b.userid 

我想在b中的所有用户ID中加入所有用户ID,长度为4.如何在b.userid上指定Len函数,其中userid长度仅为4个字符?这是在SQL服务器

2 个答案:

答案 0 :(得分:1)

SELECT *
FROM a
INNER JOIN b ON a.userid = b.userid AND LEN(b.userid) = 4

答案 1 :(得分:1)

...
JOIN db_abc b
    ON a.userid = b.userid
        AND LEN(b.userid) = 4
...