0
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

alter PROCEDURE [dbo].[TCCPAUsersAndNamesByJobPosition] @EmpOrfreeLance bit

AS
BEGIN
    SET NOCOUNT ON;

    SELECT distinct t1.UserId , tblCustomers.name 
    FROM tblTime t1
    inner join tblCustomers on t1.UserId=tblCustomers.custID
    where (t1.userid in (select distinct custID from tblCustomers where sectionCat Like '%,35%') )
    AND (t1.UserId in (select distinct custID from tblCustomers where IsEmployee = @EmpOrfreeLance))

end

も試してみました IsEmployee = CONVERT(bit,@EmpOrfreeLance)

SET @EmpOrfreeLance= CASE @EmpOrfreeLance WHEN 1 THEN 0 ELSE 0 END

何があっても同じ結果で同じリストを返します

シンプルじゃないですか???

IsEmployeecol-データ型は(bit,null)

私の開発用SQLサーバーは2008年です..オンラインサーバーは2005年です...

4

3 に答える 3

2

何かが足りないかもしれませんが、このようにクエリを書いてみませんか?

SELECT distinct t1.UserId, tblCustomers.name 
FROM tblTime t1
inner join tblCustomers on t1.UserId=tblCustomers.custID
where sectionCat Like '%,35%' AND 
      ISNULL(IsEmployee, CAST(0 As bit)) = @EmpOrfreeLance

IsEmployeeまた、が null の場合に何をするかを決定する必要があります。(それは従業員かどうか)たとえば、値ISNULL(IsEmployee, CAST(0 As bit))を処理するために a を使用します。NULLfalse

于 2012-10-29T22:16:15.557 に答える
2

null 値を比較すると、常に false が返されます。IsEmployee は null になる可能性があると述べましたが、これはおそらくあなたのケースです。

1 == NULL => False
0 == NULL => False
NULL == NULL => False

比較のために次のようなものを使用してみてください。

(@EmpOrfreeLance IS NULL
    OR IsEmployee IS NULL
    OR IsEmployee = @EmpOrfreeLance)

または

ISNULL(IsEmployee, 0) = ISNULL(@EmpOrfreeLance, 0)
于 2012-10-29T22:08:52.393 に答える
0

私は何かを逃したので間違っていた

    SELECT distinct t1.UserId , tblCustomers.name 
    FROM tblTime t1
    inner join tblCustomers on t1.UserId=tblCustomers.custID
    where (t1.userid in (select distinct custID from tblCustomers where sectionCat Like '%,35%') )
    AND (t1.UserId in (select distinct custID from tblCustomers where IsEmployee = @EmpOrfreeLance))
AND (isActive = 1 AND isActiveAgent  = 1 AND sivug Like '%,35%' AND custType = 1) 
or (isActive  = 1 AND isActiveAgent  = 1 AND sivug Like '%,35%' AND custType = 3) 
or (isActive  = 1 AND isActiveAgent  = 1 AND sivug Like '%,35%' AND custType  between  5 AND 12 )

すべてのデータを表示したくありませんでした。また、出力した他の行に OR があることに注意しませんでした。

だから私もそこに追加しなければならなかった

于 2012-10-29T22:26:39.917 に答える