word count a user

1

Please login or register to vote for this query.

(click on this box to dismiss)

Physics

Q&A for active researchers, academics and students of physics

DECLARE @total_count int, @vendor_id int, @vendor_name nvarchar(max);  

SET @total_count = 0;

DECLARE vendor_cursor CURSOR FOR
SELECT id, Body
FROM posts 
WHERE posts.OwnerUserId = 9872;

OPEN vendor_cursor

FETCH NEXT FROM vendor_cursor   
INTO @vendor_id, @vendor_name
PRINT FORMATMESSAGE('  id  | count')
WHILE @@FETCH_STATUS = 0
BEGIN
    DECLARE @count int;
    SELECT @count = (LEN(@vendor_name ) - LEN(replace(@vendor_name , ' ', '')))
    SELECT @total_count = @total_count + @count
    PRINT FORMATMESSAGE('%d |   %d  | %d', @vendor_id, @count, @total_count)
    FETCH NEXT FROM vendor_cursor
    INTO @vendor_id, @vendor_name
END

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results