且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server-具有多个字段的IN子句

更新时间:2021-08-09 03:36:42

不是您发布的方式.您只能返回单个字段或键入IN才能正常工作.

Not the way you have posted. You can only return a single field or type for IN to work.

从MSDN( IN ):

From MSDN (IN):

test_expression [ NOT ] IN 
    ( subquery | expression [ ,...n ]
    ) 

subquery - Is a subquery that has a result set of one column. 
           This column must have the same data type as test_expression.

expression[ ,... n ] - Is a list of expressions to test for a match. 
                       All expressions must be of the same type as 
                       test_expression.

您可以在两个字段中使用JOIN代替IN:

Instead of IN, you could use a JOIN using the two fields:

SELECT U.* 
FROM user U
  INNER JOIN userType UT
    ON U.code = UT.code
    AND U.userType = UT.userType