One, SQL based on a comma-delimited ID string of the type of person GUID to find its corresponding name is also stitched together into a comma-separated string:
1, demand: The administrator sends the notice (the notice divides into the general notice, the prize order, the questionnaire three types) to the user, and can view the statistic which person has viewed, which has not been viewed.
2. database table design: Notice form, Personnel table, Prize order form, questionnaire 3 tables, user notification form
3, SQL Statement inquiry has been sent notification information:
SelectA.*, E.noread,e.alread,tousername= STUFF((SELECT ',' +Name fromUsers Dwhere PATINDEX('%,' + RTRIM(account)+ ',%',',' +A.touserid+ ',')>0 ORDER by PATINDEX('%,' + RTRIM(account)+ ',%',',' +A.touserid+ ',')--plus Sort the same (for example: 2,1,3) forXML PATH ("')),1,1,"'),
CaseA.noticetypeid when 2 Then 'Survey Questionnaire' when 3 Then 'Prize Order' Else 'General Notice' End asNoticetypename,b.awardordertitle,
B.awardorderdescription,c.questionnairetitle fromnotices a Left JoinAwardorders b onA.awardorderid=b.ID andB.status=1 Left JoinQuestionnairesinfor C onA.questionnaireid=C.id andC.status=1 Left Join(SelectNoticeid,COUNT(1) asSumcount,noread=sum( Case [Status] when 1 Then 1 Else 0 End),
Alread= sum( Case [Status] when 2 Then 1 Else 0 End)
fromUsernoticesGroup byNoticeid) E onA.noticesid=E.noticeidwhereA.status=1
The notification is sent to the user notification table according to the ID string of the comma-separated user GUID type stored in field Touserid:
1. Requirement: Distribute the notification to individual users (save to user table according to user's stripe)
2, the database design the same
3. SQL Send notification:
Insert intoUsernotices (Id,noticeid,noticetype,awardsorderid,questionnaireid,creatmanaccount,creatmanname,creatdate,[Status]) ( Select NEWID(), Noticesid,noticetypeid,awardorderid,questionnaireid,b.account,b.name,GETDATE(),1
fromNotices a Left JoinUsers b on PATINDEX('%,' + RTRIM(account)+ ',%',',' +A.touserid+ ',')>0
whereA.noticesid=@NoticeID)--@NoticeID is the parameter notification ID
Problems with SQL Server string concatenation and disassembling table queries