except

  • hi

    i want to do something like this, is it possible?if not what other option

    EXECUTE sp_executesql @emp

    except

    EXECUTE sp_executesql @dept

    both emp and dept has select statement,with same number of columns

  • coool_sweet - Monday, July 17, 2017 9:08 PM

    hi

    i want to do something like this, is it possible?if not what other option

    EXECUTE sp_executesql @emp

    except

    EXECUTE sp_executesql @dept

    both emp and dept has select statement,with same number of columns

    Try something like this

    CREATE TABLE #emp (...);
    INSERT INTO #emp (...)
    EXECUTE sp_executesql @emp;

    CREATE TABLE #dept (...);
    INSERT INTO #dept (...)
    EXECUTE sp_executesql @dept;

    SELECT * FROM #emp
    EXCEPT
    SELECT * FROM #dept

  • Does this work?

    DECLARE @sql nvarchar(max) = @emp +N'
     EXCEPT
    '+@dept;
    EXEC sp_ExcueSQL @sql;

  • coool_sweet - Monday, July 17, 2017 9:08 PM

    hi

    i want to do something like this, is it possible?if not what other option

    EXECUTE sp_executesql @emp

    except

    EXECUTE sp_executesql @dept

    both emp and dept has select statement,with same number of columns

    First, no.  You have to put the data into tables first.  Second, without seeing what the output from each of the procedures looks like, just because they have the same number of columns doesn't mean that the EXCEPT makes any sense.

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

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