Results 1 to 3 of 3

Thread: switching in()

  1. #1
    Join Date
    Jan 2003
    Posts
    26

    Unanswered: switching in()

    Hi!

    I want to do:

    "WHERE kek IN (SELECT kek FROM bop WHERE id=123)"

    But I only want to do that if the subquery returns something. If it's empty then I want to accept anything.


    It should work like what you can do if you use the equal-operator (=)

    "WHERE kek = case kek when '' then kek else @kek end"

  2. #2
    Join Date
    Apr 2003
    Location
    Israel
    Posts
    81
    Try:

    WHERE

    (
    NOT EXISTS (select kek from bop where id=123)
    OR
    kek IN (SELECT kek FROM bop WHERE id=123)
    )
    --
    kukuk

  3. #3
    Join Date
    Jan 2003
    Posts
    26
    Thank you, but that was to slow.

    I made my own function.

    Code:
    CREATE   FUNCTION kek
    (
    	@userID INT
    )
    RETURNS @ret TABLE (bop nvarchar(50))
    AS
    BEGIN
    	if exists(SELECT kek FROM bop WHERE id=@userid)
    		INSERT INTO @ret SELECT kek FROM bop WHERE id=@userid
    	else
    		INSERT INTO @ret SELECT kek FROM allbops
    
    	RETURN
    END

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •