Advertisement
Guest User

Untitled

a guest
Feb 13th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.07 KB | None | 0 0
  1. Skip to content
  2.  
  3. Search or jump to
  4.  
  5. Pull requests
  6. Issues
  7. Marketplace
  8. Explore
  9.  @Jithra Sign out
  10. 0
  11. 0 0 Jithra/JithBot
  12.  Code  Issues 0  Pull requests 0  Projects 0  Wiki  Insights  Settings
  13. JithBot/MSQL Code/Stored Procedures/messagestat.sql
  14. 9dabd7f  on Oct 29, 2018
  15.  Brooke Moss Updating SQL code
  16. We found a potential security vulnerability in one of your dependencies.
  17. Only the owner of this repository can see this message.
  18. Manage your notification settings or learn more about vulnerability alerts.
  19.  
  20.      
  21. 53 lines (48 sloc)  3.06 KB
  22. USE [db_discord]
  23. GO
  24. /****** Object:  StoredProcedure [dbo].[messagestat]    Script Date: 10/29/2018 11:11:24 AM ******/
  25. SET ANSI_NULLS ON
  26. GO
  27. SET QUOTED_IDENTIFIER OFF
  28. GO
  29. ALTER PROC [dbo].[messagestat] @word VARCHAR(100), @serverid VARCHAR(100)
  30. AS
  31. BEGIN
  32. SET NOCOUNT ON
  33. SET QUOTED_IDENTIFIER OFF
  34. IF OBJECT_ID('tempdb..#jbdev') IS NOT NULL DROP TABLE tempdb..#jbdev
  35. CREATE TABLE #jbdev
  36. (
  37.     UserName VARCHAR(100),
  38.     WordCount INT
  39. )
  40.  
  41. IF OBJECT_ID('tempdb..#wordcount') IS NOT NULL DROP TABLE tempdb..#wordcount
  42. CREATE TABLE #wordcount
  43. (
  44.     UserName VARCHAR(100),
  45.     MessageCount INT
  46. )
  47. EXECUTE('
  48. INSERT INTO #jbdev
  49. SELECT tm.[User Name], tm.[Fuck Count]
  50. FROM(
  51.     SELECT UserName AS ''User Name'', COUNT(UserMessage) AS ''Fuck Count''
  52.     FROM tblAggregateDiscordLogs(NOLOCK)
  53.     WHERE UserMessage LIKE ''%' + @word + '%''
  54.     AND ServerID = ''' + @serverid + '''
  55.     GROUP BY UserName
  56. )tm
  57. INSERT INTO #wordcount
  58. SELECT tm2.[User Name], tm2.[Word Count]
  59. FROM(
  60.     SELECT UserName AS ''User Name'', COUNT(UserMessage) AS ''Word Count''
  61.     FROM tblAggregateDiscordLogs(NOLOCK)
  62.     WHERE ServerID = ''' + @serverid + '''
  63.     GROUP BY UserName
  64. ) tm2
  65. SELECT MAX(j.UserName) AS ''UserName'', MAX(MessageCount) AS ''Message Count'', MAX(WordCount) AS ''' + @word + ' count'', CONVERT(VARCHAR,ROUND(CONVERT(FLOAT,MAX(WordCount)) / CONVERT(FLOAT,MAX(MessageCount)) * 100, 2, 1)) + ''%'' AS ''' + @word + ' Percentage''
  66. FROM #jbdev j (NOLOCK)
  67. INNER JOIN #wordcount w (NOLOCK) ON j.UserName = w.UserName
  68. GROUP BY w.UserName
  69. ORDER BY MAX(WordCount) DESC');
  70. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement