Skip to content Skip to sidebar Skip to footer

Insert Update Data Help In SQL Server

I have a insert update procedure where I am getting data from 2 procedures and putting the data in to a table. So procedure 1 has data like this AgentName Tickets Closed --------

Solution 1:

You need to get data from tables Table1, @TicketsComplited, @TicketsActiv with no match

SELECT * FROM
Table1 eps FULL JOIN 
@TicketsCompleted ptc
On eps.date1=ptc.Date1
and eps.Agent=ptc.Agent
Where eps.date1 is null 
or ptc.Date1 is null 
Or eps.Agent is null 
or ptc.Agent is null



    SELECT * FROM
    Table1 eps FULL JOIN 
    @TicketsActive ptc
    On eps.date1=ptc.Date1
    and eps.Agent=ptc.Agent
    Where eps.date1 is null 
    or ptc.Date1 is null 
    Or eps.Agent is null 
    or ptc.Agent is null
   
   

Solution 2:

Well if I'm getting you correctly, I can suggest you to use one of the two below approaches.

...
SELECT COLUMNS_YOU_WANT FROM 
(
   QUERY_FOR_SOME_FILTERING
   WHERE YOUR_UNIQUE_COL NOT IN 
   (
      QUERY_FOR_SOME_FILTERING
   )
)
SELECT COL1, COL2, etc. 
FROM 
    QUERY_FOR_SOME_FILTERING
EXCEPT 
(
    SELECT COL1, COL2, etc. FROM 
    QUERY_FOR_SOME_FILTERING
)

Post a Comment for "Insert Update Data Help In SQL Server"