Select

  • Here I want to select all rows if userid is 1 or 2 if not I want to select all where OID=@OID...am I doing the right way? but when I test I cudnt get the result as expected.

    CREATE PROCEDURE spGetOppsForType

    (

    @OTID int,

    @OID int,

    @user-id int

    )

    As

    set nocount on

    IF (@UserID =1 or @userid=2)

    SELECT DISTINCT EID, EName from Emp o inner join GrpIn i

    ON o.OID=i.OID where o.OTID =@OTID

    and o.OInd = 'N' and i.UserID='1' or i.UserID='2'

    and o.OID = isNull(@OID,o.OID)

    ELSE

    SELECT EID,EName from Emp o inner join GrpIn i

    ON o.OID=i.OID

    where OTID =@OTID

    and OInd = 'N'

    and OID = @OID

    return

    GO

  • SELECT EID,EName

    from Emp o

    inner join GrpIn i ON o.OID=i.OID

    where OTID = @OTID and OInd = 'N'

    and (O.OID = @OID OR @user-id =1 or @userid=2)

    You did not tell why and when you need i.UserID='6' or i.UserID='7'

    _____________
    Code for TallyGenerator

  • pls check the update in my store proc

  • OK, then my query must return right result.

    Did you try it?

    _____________
    Code for TallyGenerator

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply