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.
| Author |
Topic |
|
c9dw2rm8
Starting Member
2 Posts |
Posted - 2010-05-14 : 08:27:03
|
Hi,I need to convert this Access SQL command to SQL SERVER COMMAND - I try to llok for examples in the Internet but non of themhad the same logic as here
"TRANSFORM First(tblStudentsMeetingsRelation.studentStatus) AS FirstOfstudentStatusSELECT tblStudentsMeetingsRelation.studentId, tblStudents.studentFirstName, tblStudents.studentLastNameFROM tblStudents INNER JOIN tblStudentsMeetingsRelation ON tblStudents.studentId = tblStudentsMeetingsRelation.studentIdWHERE (((tblStudentsMeetingsRelation.studentDeptId)="372") AND ((tblStudentsMeetingsRelation.studentSeminarId)="372-3-3455-B"))GROUP BY tblStudentsMeetingsRelation.studentId, tblStudents.studentFirstName, tblStudents.studentLastNamePIVOT tblStudentsMeetingsRelation.studentMeetingId;" I will glad if Someone will help me with thatThis is the Originl Table :studentId | studentDeptId | studentSeminarId | studentMeetingId | studentStatus----------------------------------------------------------------------------------------40223059 | 372 | 372-3-3455-B | 372-1-05112010 | A40223059 | 372 | 372-3-3455-B | 372-2-05112010 | DDD40223059 | 372 | 372-3-3455-B | 372-3-05112010 | C43162007 | 372 | 372-3-3455-B | 372-1-05112010 | A43162007 | 372 | 372-3-3455-B | 372-2-05112010 | B43162007 | 372 | 372-3-3455-B | 372-3-05112010 | CAnd the result i'm looking for look like this:studentId | studentFirstName | studentLastName | 372-1-05112010 | 372-2-05112010 | 372-3-05112010----------------------------------------------------------------------------------------------------------------------40223059 | ???? | ???? | A | DDD | C43162007 | ??? | ?????? | A | B | C* Sorry for the English |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-05-14 : 10:21:13
|
| [code]select studentId, null as studentFirstName , null as studentLastName , max(case when studentMeetingId = '372-1-05112010' then studentStatus else null end) as [372-1-05112010], max(case when studentMeetingId = '372-2-05112010' then studentStatus else null end) as [372-2-05112010], max(case when studentMeetingId = '372-3-05112010' then studentStatus else null end) as [372-3-05112010]from StudentTablegroup by studentId[/code] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-14 : 12:54:22
|
or use pivot if using sql 2005 or moreSELECT studentId, studentFirstName , studentLastName,[372-1-05112010],[372-2-05112010],[372-3-05112010]FROM (SELECT studentId, studentFirstName , studentLastName , studentMeetingId, studentStatus FROM Table)tPIVOT (MAX(studentStatus) FOR studentMeetingId IN ([372-1-05112010],[372-2-05112010],[372-3-05112010]))p ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
c9dw2rm8
Starting Member
2 Posts |
Posted - 2010-05-23 : 17:51:34
|
quote: Originally posted by visakh16 or use pivot if using sql 2005 or moreSELECT studentId, studentFirstName , studentLastName,[372-1-05112010],[372-2-05112010],[372-3-05112010]FROM (SELECT studentId, studentFirstName , studentLastName , studentMeetingId, studentStatus FROM Table)tPIVOT (MAX(studentStatus) FOR studentMeetingId IN ([372-1-05112010],[372-2-05112010],[372-3-05112010]))p ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Thanks, But the Problem is that the meeting ID are Dynamic and always change , it's not always these [372-2-05112010],[372-3-05112010].You have something else ?*sorry for the english |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2010-05-23 : 18:32:42
|
| Search for Dynamic Pivot in this forum. There are plenty of posts for it. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|