>declare @Test table (id int identity, TestFld nvarchar(max)) >insert into @Test values ('Test Test Test one more Test') >insert into @Test values ('one two three four five') >insert into @Test values ('once twice once twice once twice') >declare @AllWords nvarchar(max), @ID int, @CurrentID int >select top 1 @ID = ID, @AllWords = TestFld from @Test >print @ID >select * from @Test >--while @ID is not NULL >-- begin >-- set @CurrentID = @ID >--select Item, ID from @Test T, dbo.ufn_Alines(T.TestFld,' ') having COUNT(Item) >=3 >-- select Item from dbo.ufn_Alines(@AllWords,' ') group by Item having COUNT(Item)>=3 >-- select top 1 @ID = ID, @AllWords = TestFld from @Test where ID > @CurrentID >-- END > > select top 1 @ID = ID, @AllWords = TestFld from @Test where ID > 3 > print @ID>
SET @Id = (SELECT TOP 1 Id FROM .....)