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.
| Author |
Topic |
|
ausla
Starting Member
7 Posts |
Posted - 2011-11-09 : 19:35:03
|
| Hi I am new to sql programming. anybody can help me pleaseSELECT DISTINCT (LTRIM(RTRIM(student.preferred_name)) + ' ' + LTRIM(RTRIM(student.surname))) as Student_Name, student.stud_code AS Student_Code, student.year_grp AS Year_Group FROM student, studsub, subtab, tchsub, teacher, portalusersWHERE IF <_Username = portalusers.username>portalusers.prodcode = 'WB' AND portalusers.portal_code = teacher.tch_code AND tchsub.year_num = datepart(year,getdate()) AND teacher.tch_code = tchsub.tch_code AMD tchsub.sub_code = subtab.sub_code AND subtab.sub_code = studsub.sub_code AND tchsub.class = studsub.class AND tchsub.semester = studsub.semester AND studsub.yr_study = tchsub.year_num AND studsub.stud_code = student.stud_code AND (student.year_grp > 6 and student.year_grp < 13) AND student.cmpy_code = '01'"This is my code I want to disply the student names beased on the login details i mean with the usernameCan anybody help me please. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-11-09 : 19:54:37
|
| Have a look at the CASE StatementWHERE CASE WHEN Username = portalusers.username... |
 |
|
|
ausla
Starting Member
7 Posts |
Posted - 2011-11-09 : 23:09:14
|
| I tried that but it didn't work. Its giving like incorrect syntax. can you help me please.thanx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-10 : 00:31:46
|
| [code]SELECT DISTINCT (LTRIM(RTRIM(student.preferred_name)) + ' ' + LTRIM(RTRIM(student.surname))) as Student_Name, student.stud_code AS Student_Code, student.year_grp AS Year_GroupFROM student, studsub, subtab, tchsub, teacher, portalusersWHERE (_Username <> portalusers.username OR(portalusers.prodcode = 'WB' AND portalusers.portal_code = teacher.tch_code AND tchsub.year_num = datepart(year,getdate()) AND teacher.tch_code = tchsub.tch_code AMD tchsub.sub_code = subtab.sub_code AND subtab.sub_code = studsub.sub_code AND tchsub.class = studsub.class AND tchsub.semester = studsub.semester AND studsub.yr_study = tchsub.year_num AND studsub.stud_code = student.stud_code AND (student.year_grp > 6 and student.year_grp < 13) AND student.cmpy_code = '01')[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|