Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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 = @ClassCodeSELECT e.ExamID,e.Title, e.Description, e.Duration,ed.ExamDateID,e.TotalQuestions,ed.StartDate,ed.EndDate,e.IsEditable FROM test_Exams eJOIN test_ExamDates ed ON ed.ExamID = e.ExamID WHERE e.ExamStatusID = 1 AND e.ExamTypeID = @ExamTypeIDMohammad 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 ENDFROM test_Exams eINNER JOIN test_ExamDates ed ON ed.ExamID = e.ExamID WHERE e.ExamStatusID = 1 AND e.ExamTypeID = @ExamTypeID
Tara Kizeraka tduggan
azamsharp
Posting Yak Master
201 Posts
Posted - 2006-06-01 : 16:40:01
Awesome got it !!! Thanks a million! :)Mohammad Azam www.azamsharp.net