Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USE test
- GO
- DECLARE @usr varchar(50)
- IF EXISTS(SELECT name FROM test..sysobjects WHERE name LIKE N'#usrdata' AND xtype='U')
- DROP TABLE TableName
- CREATE TABLE #usrdata
- (
- usr varchar(50),
- data varchar(50)
- )
- DELETE FROM usrdata
- DECLARE usr_cursor CURSOR FOR
- SELECT DISTINCT usr
- FROM Foo
- OPEN usr_cursor
- FETCH NEXT FROM usr_cursor
- INTO @usr
- WHILE (@@FETCH_STATUS = 0)
- BEGIN
- INSERT INTO #usrdata (usr, data)
- SELECT TOP 3 usr, data FROM Foo
- WHERE usr = @usr
- FETCH NEXT FROM usr_cursor
- INTO @usr
- END
- CLOSE usr_cursor
- DEALLOCATE usr_cursor
- SELECT * FROM #usrdata
- DROP TABLE #usrdata
Add Comment
Please, Sign In to add comment