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)
 Selecting Date from another table based on conditi

Author  Topic 

azamsharp
Posting Yak Master

201 Posts

Posted - 2006-06-01 : 16:17:41
Hi,

I have this query below. Now I want that when the IsEditable (bit) is 0 then it should select the dates fro mthe test_ExamDates table and when the IsEditable is 1 then it should select the dates from another table. How can I do that?

SELECT @ExamTypeID = ExamTypeID FROM
UserClassCodeCategories uccc WHERE uccc.ClassCode = @ClassCode

SELECT e.ExamID,e.Title, e.Description, e.Duration,ed.ExamDateID,
e.TotalQuestions,ed.StartDate,ed.EndDate,e.IsEditable FROM test_Exams e
JOIN test_ExamDates ed ON ed.ExamID = e.ExamID
WHERE e.ExamStatusID = 1
AND e.ExamTypeID = @ExamTypeID

Mohammad Azam
www.azamsharp.net

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-01 : 16:22:49
You can use a CASE statement for this.


SELECT
e.ExamID,
e.Title,
e.[Description],
e.Duration,
ed.ExamDateID,
e.TotalQuestions,
ed.StartDate,
ed.EndDate,
e.IsEditable,
NewColumn =
CASE
WHEN e.IsEditable = 0 THEN ed.SomeDateColumn
ELSE SomeOtherTable.SomeOtherDateColumn
END
FROM test_Exams e
INNER JOIN test_ExamDates ed
ON ed.ExamID = e.ExamID
WHERE
e.ExamStatusID = 1 AND
e.ExamTypeID = @ExamTypeID


Tara Kizer
aka tduggan
Go to Top of Page

azamsharp
Posting Yak Master

201 Posts

Posted - 2006-06-01 : 16:40:01

Awesome got it !!!

Thanks a million! :)

Mohammad Azam
www.azamsharp.net
Go to Top of Page
   

- Advertisement -