Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Prefix.....Help

Author  Topic 

rintus
Starting Member

26 Posts

Posted - 2008-09-18 : 12:03:04
I want to know what do I do to get the the first two characters of each subjects. I mean if a student is steve and he takes two courses say maths and science. What changes do I need to make to this SQL to get the output as -

Student_Name Prefix
Steve Ma
Steve Sc

Please help

select distinct a.name Student_name, count(b.subj)
from student a
,subject b
where b.rod_id = a.row_id
group by a.name
order by 1

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 12:35:42
no need of grouping

select a.name as Student_name,left(b.subj,2) AS Prefix
from student a
,subject b
where b.rod_id = a.row_id
Go to Top of Page

rintus
Starting Member

26 Posts

Posted - 2008-09-18 : 13:13:19
Thanks man, u r amazing
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 13:17:54
quote:
Originally posted by rintus

Thanks man, u r amazing


you're welcome
Go to Top of Page
   

- Advertisement -