declare @email nvarchar(255) declare CustList cursor for SELECT email from STE_EMAILS OPEN CustList FETCH NEXT FROM CustList INTO @email WHILE @@FETCH_STATUS = 0 BEGIN if (SELECT count(custid) from customer where (current_customer=1) and (notes1 is not null) and (notes1 like '%' + @email + '%')) > 0 SELECT custid from customer where (current_customer=1) and (notes1 is not null) and (notes1 like '%' + @email + '%') print '%' + @email + '%' FETCH NEXT FROM CustList INTO @email END CLOSE CustList DEALLOCATE CustList
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
Simple TSQL cursor (See related posts)
You need to create an account or log in to post comments to this site.
Related Posts
» Randomly ordered results in ... in sql tsql
» Dynamic ordering without dyn... in sql tsql
» find duplicates in sql tsql
» Simple COALESCE example in tsql
» Replace text in a TEXT type ... in tsql
» Retrieve MSSQL table informa... in sql server tsql mssql table microsoft column information properties sysproperties systables data type types length columns
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails