新的一週,這週末精神保持的還很好,好好幹吧!也就三週了!
上午活還挺多,要create一個新的report給graduation application,這個很好啊,造福於同學們,主要工作在SQL語句設計上,我要join幾個table調用不同信息,最後把每個學生申請的專業,小專業和具體方向放到record的主表之中。有一步要把多個cell的內容連接放到一個裏面,於是就得用到了for xml 這樣的語句,還有stuff()string insertion。代碼如下:
SELECT [id] as [ID], [studentID] as [Student ID], [firstName] as [First Name],[lastName] as [Last Name], [reqDate] as [Request Date], [email] as [Email],[gradTerm] as [Graduation Term],[honorsCollege] as [Honors College],(STUFF ((SELECT majorName+', ' FROM [GradApp_Degrees] where [GradApp_Degrees].studentID=Records.studentID for xml path ('')), 1, 0,' ') + STUFF ((SELECT minor+', ' FROM [GradApp_Minors] where [GradApp_Minors].studentID=Records.studentID for xml path ('')), 1, 0,' ')) as [Applied Minor] , STUFF ((SELECT specialization+', ' FROM [GradApp_Degrees] where [GradApp_Degrees].studentID=Records.studentID for xml path ('')), 1, 0,' ') as [Specialization] FROM [MyState_CLG].[dbo].[GradApp_Records] as Records
下午明白了不是要簡單的把兩個cell內容連起,是要有小專業的attach到大專業去,這樣我就傻逼了,於是就琢磨了一個小時,開始想用case when then end來判斷,後來發現stuff()method不能嵌套使用,於是就想到了另外加一個column,把三個table join之後select得到的內容,然後join來join去又花了半個小時,最後得出正確結果。
SELECT [id] as [ID],
[studentID] as [Student ID],
[firstName] as [First Name],
[lastName] as [Last Name],
[reqDate] as [Request Date],
[email] as [Email],
[gradTerm] as [Graduation Term],
[honorsCollege] as [Honors College],
STUFF (
(SELECT distinct Degree.majorName + '; '
FROM [MyState_CLG].[dbo].[GradApp_Degrees] Degree
join [MyState_CLG].[dbo].[GradApp_Records] Records
on Degree.studentID=Records.studentID for xml path ('')), 1, 0,' ') as [Applied Major] ,
STUFF (
(SELECT distinct Degree.majorName + '('+Minors.minor
+'); 'FROM [MyState_CLG].[dbo].[GradApp_Degrees] Degree join [MyState_CLG].[dbo].[GradApp_Minors] Minors
on Degree.majorName = Minors.majorName and Minors.studentID = Degree.studentID
join [MyState_CLG].[dbo].[GradApp_Records] Records
on Degree.studentID=Records.studentID for xml path ('')), 1, 0,' ') as[Applied Minor] ,
STUFF ((SELECT distinct specialization+'; ' FROM [MyState_CLG].[dbo].[GradApp_Degrees]
where [MyState_CLG].[dbo].[GradApp_Degrees].studentID=Records.studentID for xml path ('')), 1, 0,' ') as [Specialization]
FROM [MyState_CLG].[dbo].[GradApp_Records] as Records
今下午insidestate的server看來是正在升級,於是幹不了report的事了,從今天開始學校就開始用sharepoint 2013了!
SQL裏面有時候報錯說找不到object,是因爲沒有put full DB名字,可以兩種方法,在一組服務器上郵件new query,或者在new query裏面加上use webforms就可以了。
最後把一個mockup做了,一個印第安orientation的申請表,挺有意思。