SQL Server expert needed for Stored Procedure
Budget: $30 – $250 USD
Hello,
I need someone to create a Stored Procedure (SP) for me in SQL Server 2019. I have the following table called "Questions":
ID uniqueidentifier
CategoryID uniqueidentifier
Question nvarchar(max)
Answer1 nvarchar(max)
Answer2 nvarchar(max)
Answer3 nvarchar(max)
Answer4 nvarchar(max)
CorrectAnswer as tinyint
It's for a simple quiz application. The table should be self-explanatory except CategoryID, which is the category for the question (e.g. History, Math, Sport, etc.). I have another table called "Categories" listing the categories:
ID uniqueidentifier
ParentID uniqueidentifier
CategoryName nvarchar(max)
Please note categories can be HIERARCHICAL, I can have the following simply categories:
--- History
--- Math
--- Sports
But I can also have the following categories:
--- Home
------ History
--------- 1st World War
--------- 2st World War
------ Math
--------- Algebra
------------ Median algebra
------------ Modern algebra
------------ Shuffle algebra
------ Sports
--------- Footbal
--------- Baskeball
------------ NBA 2020
------------ NBA 2021
Levels could be theorically unlimited (pratically I have a max level depth of 15 levels).
I also have the following JSON:
[
{
"CategoryId": "a4ae4b6e-50cf-4058-b456-a26ed165dd39",
"QuestionsToExtract": 3
},
{
"CategoryId": "e02b26ed-1828-422c-b5a0-375d267de159",
"QuestionsToExtract": 3
},
{
"CategoryId": "17aa1c7f-6993-4a92-af17-32a2342f336b",
"QuestionsToExtract": 4
}
]
I need a Store Procedure that, taking the json as parameter, it returns me a list of questions extracted according to the rules specified in the json: for example, with the above json it should return 10 questions (3 RANDOM questions from categoryID=a4ae4b6e-50cf-4058-b456-a26ed165dd39 [or sublevels], 3 RANDOM questions from categoryID=e02b26ed-1828-422c-b5a0-375d267de159 [or sublevels] and 4 RANDOM questions from categoryID=17aa1c7f-6993-4a92-af17-32a2342f336b [or sublevels], for a total of 10 questions).
The stored procedure may be called dozen times per second, so it should be VERY OPTIMIZED, and it should not use CURSORS or LOOPS.
Some examples to better understand the problem:
1) If the category to extract from is Sports, it should extract random questions contained in Sports OR Football OR Basketball OR NBA 2020 OR NBA 2021
2) If the category to extract from is Basketball, it should extract random questions contained in Basketball OR NBA 2020 OR NBA 2021
3) If the category to extract from is Modern algebra, it should extract random questions contained in Modern algebra
4) If the category to extract from is Home, it should extract random questions contained in any of the subcategories
For any information, just ask.
Thanks.
I need someone to create a Stored Procedure (SP) for me in SQL Server 2019. I have the following table called "Questions":
ID uniqueidentifier
CategoryID uniqueidentifier
Question nvarchar(max)
Answer1 nvarchar(max)
Answer2 nvarchar(max)
Answer3 nvarchar(max)
Answer4 nvarchar(max)
CorrectAnswer as tinyint
It's for a simple quiz application. The table should be self-explanatory except CategoryID, which is the category for the question (e.g. History, Math, Sport, etc.). I have another table called "Categories" listing the categories:
ID uniqueidentifier
ParentID uniqueidentifier
CategoryName nvarchar(max)
Please note categories can be HIERARCHICAL, I can have the following simply categories:
--- History
--- Math
--- Sports
But I can also have the following categories:
--- Home
------ History
--------- 1st World War
--------- 2st World War
------ Math
--------- Algebra
------------ Median algebra
------------ Modern algebra
------------ Shuffle algebra
------ Sports
--------- Footbal
--------- Baskeball
------------ NBA 2020
------------ NBA 2021
Levels could be theorically unlimited (pratically I have a max level depth of 15 levels).
I also have the following JSON:
[
{
"CategoryId": "a4ae4b6e-50cf-4058-b456-a26ed165dd39",
"QuestionsToExtract": 3
},
{
"CategoryId": "e02b26ed-1828-422c-b5a0-375d267de159",
"QuestionsToExtract": 3
},
{
"CategoryId": "17aa1c7f-6993-4a92-af17-32a2342f336b",
"QuestionsToExtract": 4
}
]
I need a Store Procedure that, taking the json as parameter, it returns me a list of questions extracted according to the rules specified in the json: for example, with the above json it should return 10 questions (3 RANDOM questions from categoryID=a4ae4b6e-50cf-4058-b456-a26ed165dd39 [or sublevels], 3 RANDOM questions from categoryID=e02b26ed-1828-422c-b5a0-375d267de159 [or sublevels] and 4 RANDOM questions from categoryID=17aa1c7f-6993-4a92-af17-32a2342f336b [or sublevels], for a total of 10 questions).
The stored procedure may be called dozen times per second, so it should be VERY OPTIMIZED, and it should not use CURSORS or LOOPS.
Some examples to better understand the problem:
1) If the category to extract from is Sports, it should extract random questions contained in Sports OR Football OR Basketball OR NBA 2020 OR NBA 2021
2) If the category to extract from is Basketball, it should extract random questions contained in Basketball OR NBA 2020 OR NBA 2021
3) If the category to extract from is Modern algebra, it should extract random questions contained in Modern algebra
4) If the category to extract from is Home, it should extract random questions contained in any of the subcategories
For any information, just ask.
Thanks.