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
 General SQL Server Forums
 New to SQL Server Programming
 if condition within where clause

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 please

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_Group
FROM student, studsub, subtab, tchsub, teacher, portalusers
WHERE 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 username
Can anybody help me please.

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-11-09 : 19:54:37
Have a look at the CASE Statement


WHERE CASE WHEN Username = portalusers.username...
Go to Top of Page

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
Go to Top of Page

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_Group
FROM student, studsub, subtab, tchsub, teacher, portalusers
WHERE (_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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -