Click here to Skip to main content
15,920,633 members
Home / Discussions / Database
   

Database

 
AnswerRe: query to get results from 4 tables Pin
venu65617-Feb-09 1:45
venu65617-Feb-09 1:45 
GeneralRe: query to get results from 4 tables Pin
icanmakeiteasy17-Feb-09 1:57
icanmakeiteasy17-Feb-09 1:57 
AnswerRe: query to get results from 4 tables Pin
icanmakeiteasy17-Feb-09 22:45
icanmakeiteasy17-Feb-09 22:45 
QuestionCASE when false query [modified] Pin
foryou16-Feb-09 23:40
foryou16-Feb-09 23:40 
AnswerRe: CASE when false query Pin
foryou17-Feb-09 1:02
foryou17-Feb-09 1:02 
GeneralRe: CASE when false query Pin
Wendelius17-Feb-09 7:57
mentorWendelius17-Feb-09 7:57 
GeneralRe: CASE when false query Pin
foryou17-Feb-09 22:47
foryou17-Feb-09 22:47 
GeneralRe: CASE when false query Pin
Wendelius18-Feb-09 7:37
mentorWendelius18-Feb-09 7:37 
It didn't come out very pretty Smile | :) but could you use this for somekind of starting point. The idea is that the first query gets the records where the student is absent and the second gets those where the student isn't absent. then these are joined and columns are combined:
SELECT coalesce(a.ID_STUDENT, b.ID_STUDENT) as id_student,
		coalesce(a.note1, b.note1) as note1,
		coalesce(a.note2, b.note2) as note2,
		coalesce(a.note3, b.note3) as note3
FROM 
(SELECT ID_STUDENT, 
        CASE WHEN ([121]) = 0 THEN 'Abs' ELSE CONVERT(varchar, [121]) END AS note1,       
        CASE WHEN ([122]) = 0 THEN 'Abs' ELSE CONVERT(varchar, [122]) END AS note2,       
        CASE WHEN ([123]) = 0 THEN 'Abs' ELSE CONVERT(varchar, [123]) END AS note3
FROM (SELECT ID_FIELD, ID_STUDENT, NOTE
FROM EXAMEN WHERE code = 1) p 
PIVOT (sum(NOTE) FOR ID_FIELD IN ([121], [122], [123])) AS pvt) a
full outer join 
(SELECT ID_STUDENT, 
       CONVERT(varchar, [121]) AS note1,
       CONVERT(varchar, [122]) AS note2,
       CONVERT(varchar, [123]) AS note3
FROM (SELECT ID_FIELD, ID_STUDENT, NOTE
FROM EXAMEN WHERE code = 0) p 
PIVOT (sum(NOTE) FOR ID_FIELD IN ([121], [122], [123])) AS pvt) b
on a.ID_STUDENT = b.ID_STUDENT

The result is:
id_student  note1  note2  note3
----------  -----  -----  -----
9306        Abs    4      12
9307        3      Abs    9
9308        12     4      9


The need to optimize rises from a bad design.My articles[^]

GeneralRe: CASE when false query Pin
foryou19-Feb-09 1:55
foryou19-Feb-09 1:55 
GeneralRe: CASE when false query Pin
Wendelius19-Feb-09 5:53
mentorWendelius19-Feb-09 5:53 
GeneralFormulas in SQL Server Reporting Services Pin
dboy22116-Feb-09 11:04
dboy22116-Feb-09 11:04 
GeneralRe: Formulas in SQL Server Reporting Services Pin
Diving Flo17-Feb-09 23:44
Diving Flo17-Feb-09 23:44 
QuestionIn search of a better solution... Pin
Jörgen Sigvardsson16-Feb-09 6:50
Jörgen Sigvardsson16-Feb-09 6:50 
AnswerRe: In search of a better solution... [modified] Pin
Wendelius16-Feb-09 7:04
mentorWendelius16-Feb-09 7:04 
GeneralRe: In search of a better solution... Pin
Jörgen Sigvardsson16-Feb-09 8:35
Jörgen Sigvardsson16-Feb-09 8:35 
GeneralRe: In search of a better solution... Pin
Wendelius17-Feb-09 1:26
mentorWendelius17-Feb-09 1:26 
GeneralRe: In search of a better solution... Pin
Jörgen Sigvardsson17-Feb-09 1:34
Jörgen Sigvardsson17-Feb-09 1:34 
GeneralRe: In search of a better solution... Pin
Wendelius17-Feb-09 2:10
mentorWendelius17-Feb-09 2:10 
GeneralRe: In search of a better solution... Pin
Jörgen Andersson17-Feb-09 2:53
professionalJörgen Andersson17-Feb-09 2:53 
GeneralRe: In search of a better solution... Pin
Jörgen Sigvardsson17-Feb-09 1:34
Jörgen Sigvardsson17-Feb-09 1:34 
GeneralRe: In search of a better solution... Pin
Wendelius17-Feb-09 2:10
mentorWendelius17-Feb-09 2:10 
AnswerRe: In search of a better solution... Pin
Ennis Ray Lynch, Jr.17-Feb-09 5:15
Ennis Ray Lynch, Jr.17-Feb-09 5:15 
AnswerRe: In search of a better solution... Pin
PIEBALDconsult17-Feb-09 16:15
mvePIEBALDconsult17-Feb-09 16:15 
GeneralRe: In search of a better solution... Pin
Jörgen Sigvardsson17-Feb-09 20:58
Jörgen Sigvardsson17-Feb-09 20:58 
QuestionFull Text Query Pin
Muhammad Fahim Baloch16-Feb-09 4:51
Muhammad Fahim Baloch16-Feb-09 4:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.