June 15, 2009 at 11:47 pm
Hello,
Please help me to write a query of students exams result.
I want place a * with students got >=40 and <60 percent marks.
I want place a ** with students got >=60 and <75 percent marks.
I want place a *** with students got >=75 percent marks.
Example
Student Name Marks
Mr. A* 45
Mr. B** 67
Mr. C*** 78
Mr. D 35
Please advice as early as possible.
June 15, 2009 at 11:56 pm
pankaj.srivastav (6/15/2009)
Hello,Please help me to write a query of students exams result.
I want place a * with students got >=40 and =60 and =75 percent marks.
Example
Student Name Marks
Mr. A* 45
Mr. B** 67
Mr. C*** 78
Mr. D 35
Please advice as early as possible.
select Stu_name=
case
When marks>=40 and marks=60 and marks=75 then stu_name+'***'
else stu_name
END,
marks from Student_Table
Also go through http://www.sqlservercentral.com/articles/Best+Practices/61537/%5B/URL%5D if you need better assistance.
June 15, 2009 at 11:58 pm
Give me the table structure ....
Abhay Chaudhary
Sr.DBA (MCITP/MCTS :SQL Server 2005/2008 ,OCP 9i)
June 16, 2009 at 12:06 am
You got the answer ....:-)
I was thinking it other way sa if you need to add stars to marks ...
But still if you need it i have copied the small repro below using cast ..
might or might not help but will add to your knowledge ..
declare @marks-2 int
declare @stars varchar (3)
set @marks-2 = 40
set @stars='***'
select cast(@marks as varchar(3)) + @stars
Abhay Chaudhary
Sr.DBA (MCITP/MCTS :SQL Server 2005/2008 ,OCP 9i)
June 16, 2009 at 6:36 pm
Hi,
Use CASE expression within SELECT statement to get your desired result.
cheers
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply