Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Please help me to write the logic for this critical requirement in TSQL!

$
0
0
Hi, 
I have a critical requirement. Please help me to resolve this. Below are the DDLs.

Create table Student
(
StudentName varchar(50),StudentID bit,InCricket bit,InFootball bit,
InHockey bit,InMaths bit,InScience bit,InComputer bit,
InChess bit,InCarrom bit,InActing bit,InDance bit,InSinging bit)

Go

insert into student values ('Jockson', '1001',0,0,0,0,0,0,0,0,0,1,1)
insert into student values ('Ronaldo', '1002',0,1,0,0,0,0,0,0,0,0,0)
insert into student values ('Newton', '1003',0,0,0,0,1,0,1,0,0,0,0)
insert into student values ('Siddhu', '1004',1,0,0,0,0,0,1,0,0,1,1)
insert into student values ('Sachin', '1005',1,1,1,1,1,1,1,1,1,1,1)


The requirement is to give 'Score' and 'Catagory' for students.ie)

If the student has any of the below

InCricket, InFootball,InHockey values = 1 in the table then his score is 1 and catagory is 'Sportman'  and 

If  if he has any of the 

InMaths ,InScience ,InComputer= 1 then his score is 1 and catagory is 'Nerd'

If the student has any of the below

InChess ,InCarrom= 1 then his score is 1 and catagory is 'Indoor Sportman'

If the student has any of the below

InActing,InDance ,InSinging= 1  his score is 1 and catagory is 'Stage Performer'


So, I have to write a Stored Procedure or function and pass a StudentID, it should display hisTotal Score and All his catagories.

Eg. If I pass StudentID 1001 to that function, it should retreive the below values

Score   catagory
1       Stage Performer

Eg. If I pass StudentID 1002 to that function, it should retrive the below values

Score  catagory
1         Sportsman

Eg. If I pass StudentID 1003 to that function, it should retrive the below values

Score  catagory
2         Nerd
           Indoor Sportsman

Eg. If I pass StudentID 1004 to that function, it should retrieve the below values

Score  catagory
3      Sportsman
       Indoor sportsman
       Stage performer

Eg. If I pass StudentID 1005 to that function, it should retrieve the below values

Score  catagory
4      Sportsman
        Nerd
        Indoor sportsman
         Stage performer

Can you please help me to write a function or procedure with the logic?

Thanks in advance!

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>