Correlated subquery in SQL

后端 未结 2 1267
野性不改
野性不改 2021-01-23 23:12

I have two tables: Table A and Table B

  1. Table A and Table B both have RowId column.
  2. Table A and Table B both have ModifiedAt col
2条回答
  •  不要未来只要你来
    2021-01-23 23:33

    DECLARE @RowId INT

    DECLARE CurRowId CURSOR FOR SELECT RowId FROM Patients

    OPEN CurRowId

    FETCH NEXT FROM CurRowId INTO @RowId

    WHILE @@FETCH_STATUS = 0

    BEGIN

    if not exists (select * from dbo.ResultsStored where ModifiedAt >

                     (select ModifiedAt from dbo.Patients where RowId = 
                                                                       @RowId))
    

    begin

    print'not exists'

    end
    
    else
    
    begin
    
    print 'exists'
    
    END
    
    FETCH  NEXT FROM CurRowId INTO @RowId
    
    END
    

提交回复
热议问题