Nov 5, 2009 #1 LAM986 Programmer Nov 4, 2009 15 US Hello, My data looks like: StudentID Review1 Review2 228017 12/30/2008 NULL 228017 3/12/2009 NULL I want it to look like: StudentID Review1 Review2 228017 12/30/2008 3/12/2009 I'm using a simple SELECT StudentID , max(Review1) , max(Review2) FROM WBLP Thank you
Hello, My data looks like: StudentID Review1 Review2 228017 12/30/2008 NULL 228017 3/12/2009 NULL I want it to look like: StudentID Review1 Review2 228017 12/30/2008 3/12/2009 I'm using a simple SELECT StudentID , max(Review1) , max(Review2) FROM WBLP Thank you
Nov 5, 2009 #2 markros Programmer May 21, 2007 3,150 US select S.StudentID, Min(Review1) as Review1, Max(Review1) as Review2 from WBLP would this work? Upvote 0 Downvote
Nov 6, 2009 Thread starter #3 LAM986 Programmer Nov 4, 2009 15 US I tried that and I get StudentID Review1 Review2 228017 12/30/2008 NULL Thanks for responding Upvote 0 Downvote
Nov 6, 2009 #4 bborissov Programmer May 3, 2005 5,167 BG nope, you didn't tried it right Code: select S.StudentID, Min(Review1) as Review1, Max([COLOR=red][b]Review1[/b][/color]) as Review2 FROM WBLP Borislav Borissov VFP9 SP2, SQL Server 2000/2005. Upvote 0 Downvote
nope, you didn't tried it right Code: select S.StudentID, Min(Review1) as Review1, Max([COLOR=red][b]Review1[/b][/color]) as Review2 FROM WBLP Borislav Borissov VFP9 SP2, SQL Server 2000/2005.
Nov 6, 2009 #5 markros Programmer May 21, 2007 3,150 US Based on the data you posted you should have gotten the correct result (not NULL) using the query I provided. Upvote 0 Downvote
Based on the data you posted you should have gotten the correct result (not NULL) using the query I provided.
Nov 6, 2009 Thread starter #6 LAM986 Programmer Nov 4, 2009 15 US That worked! Thank you so much. Upvote 0 Downvote
Nov 6, 2009 #7 markros Programmer May 21, 2007 3,150 US )) Did it work because the last portion was in red? )))) Upvote 0 Downvote
Nov 6, 2009 #8 markros Programmer May 21, 2007 3,150 US Actually, there was a typo in the query - there should not be S.StudentID - should be just StudentID (also I think I meant to add GROUP BY StudentID) Upvote 0 Downvote
Actually, there was a typo in the query - there should not be S.StudentID - should be just StudentID (also I think I meant to add GROUP BY StudentID)
Nov 6, 2009 Thread starter #9 LAM986 Programmer Nov 4, 2009 15 US Makros, I'm sorry. Yours would have worked, I didn't see Review1 on the second field. I apologize. Upvote 0 Downvote
Nov 6, 2009 Thread starter #10 LAM986 Programmer Nov 4, 2009 15 US Thank you guys for your help. Upvote 0 Downvote
Nov 6, 2009 #11 markros Programmer May 21, 2007 3,150 US No problem, there were several typos in the query anyway. Upvote 0 Downvote
Nov 7, 2009 Thread starter #12 LAM986 Programmer Nov 4, 2009 15 US One more question. How do I handle if Review1 is NULL So the data looks like: StudentID Review1 Review2 228017 12/30/2008 NULL 228017 NULL NULL The result I get in this case is below, when I would now want to put NULL in review2 StudentID Review1 Review2 228017 12/30/2008 12/30/2008 Upvote 0 Downvote
One more question. How do I handle if Review1 is NULL So the data looks like: StudentID Review1 Review2 228017 12/30/2008 NULL 228017 NULL NULL The result I get in this case is below, when I would now want to put NULL in review2 StudentID Review1 Review2 228017 12/30/2008 12/30/2008
Nov 7, 2009 #13 markros Programmer May 21, 2007 3,150 US Try Code: select S.StudentID, Min(Review1) as Review1, case when min(Review1) = Max(Review1) then NULL else Max(Review1) end as Review2 FROM WBLP Upvote 0 Downvote
Try Code: select S.StudentID, Min(Review1) as Review1, case when min(Review1) = Max(Review1) then NULL else Max(Review1) end as Review2 FROM WBLP
Nov 9, 2009 Thread starter #14 LAM986 Programmer Nov 4, 2009 15 US Thanks again guys. I knew I had to do a Case statement, but couldn't get the right outcome. Upvote 0 Downvote