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 |
|
teddymeu4u
Starting Member
2 Posts |
Posted - 2010-04-08 : 09:10:38
|
| Hi GuysI have 3 tables, table 1 holds details about a message, table 2 holds the audiences the message is for, and table 3 holds details of all users who have confirmed they have read a message,What im trying to do is display, all messages for a particular user, where the publish date is greater than or equal to todays date, and where the messageid, username, does not appear in table 3, which shows they havent read the message, (Basically showing users specific messages applicable to them which they have not yet read) its for a vb.net application im building, Ive put the query below and whilst its almost write, its not doing what i want, which is bascially the part about showing the messages they havent yet read, at the moment its returning results for other users, also, i only want it to show results for the particular user, who has not yet read the particular message.SELECT commsPlatformChangeMsg.changeMsgID, commsPlatformChangeMsg.changeMsgTitle, commsPlatformChangeMsg_MuID.MU_ID, commsPlatformChangeMsg_MuID.site, commsPlatformChangeMsg.changeMsgActive, commsPlatformChangeMsg.changeMsgPublishDate, commsPlatformChangeMsg_Read.username, commsPlatformChangeMsg.changeMsgPageURL, commsPlatformChangeMsg_Read.changeMsgID AS read_MessageIDFROM commsPlatformChangeMsg INNER JOIN commsPlatformChangeMsg_MuID ON commsPlatformChangeMsg.changeMsgID = commsPlatformChangeMsg_MuID.changeMsgID CROSS JOIN commsPlatformChangeMsg_ReadGROUP BY commsPlatformChangeMsg.changeMsgID, commsPlatformChangeMsg.changeMsgTitle, commsPlatformChangeMsg_MuID.MU_ID, commsPlatformChangeMsg_MuID.site, commsPlatformChangeMsg.changeMsgActive, commsPlatformChangeMsg.changeMsgPublishDate, commsPlatformChangeMsg_Read.username, commsPlatformChangeMsg.changeMsgPageURL, commsPlatformChangeMsg_Read.changeMsgIDHAVING (commsPlatformChangeMsg_MuID.MU_ID = @MU_ID) AND (commsPlatformChangeMsg_MuID.site = @site) AND (commsPlatformChangeMsg.changeMsgActive > 0) AND (CONVERT(datetime, CONVERT(varchar(8), GETDATE(), 112)) >= CONVERT(datetime, CONVERT(varchar(8), commsPlatformChangeMsg.changeMsgPublishDate, 112))) AND (NOT (commsPlatformChangeMsg_Read.username IN (@username))) AND (NOT (commsPlatformChangeMsg.changeMsgID IN (commsPlatformChangeMsg_Read.changeMsgID)))Thanks in advance for your help and supportDanNo one ever said it was going to be easy, then again, nothing worth doing ever is. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-08 : 11:05:28
|
something likeSELECT required columns....FROM Table1 t1INNER JOIN Table2 t2ON t.messageid=t2.messageidAND t2.username = @yourpassedusernameLEFT JOIN Table3 t3ON t3.messageid = t2.messageidAND t3.username = t3.usernameWHERE t3.messageid IS NULLAND t1.publishdate > = DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
teddymeu4u
Starting Member
2 Posts |
Posted - 2010-04-09 : 04:09:03
|
| Hi visakh16 thanks for the reply, however im looking for items where the user hasnt already read them, maybe if i give you the table structures youll get a better idea.Table 1MessageID (int PK)title (varchar200)Created (smalldatetime)PageURLTable2MessageID (int)MU_ID (int)Site (varchar)Table 3messageID (int)username (varchar11)readit (smallint)Ok, so i want to know, all articles for the username, where the created date is greater than or equal to todays date, and the username and message id, doesnt appear in table 3, i am passing in th username, site, and MU_ID, in the query string as parameters.ThanksNo one ever said it was going to be easy, then again, nothing worth doing ever is. |
 |
|
|
RobertKaucher
Posting Yak Master
169 Posts |
Posted - 2010-04-09 : 10:00:05
|
| How can you determine if the user has read the message and what is the language for the front end? Does readit = some value? It would be helpful if you posted some sample data.===http://www.ElementalSQL.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-11 : 03:21:46
|
quote: Originally posted by teddymeu4u Hi visakh16 thanks for the reply, however im looking for items where the user hasnt already read them, maybe if i give you the table structures youll get a better idea.Table 1MessageID (int PK)title (varchar200)Created (smalldatetime)PageURLTable2MessageID (int)MU_ID (int)Site (varchar)Table 3messageID (int)username (varchar11)readit (smallint)Ok, so i want to know, all articles for the username, where the created date is greater than or equal to todays date, and the username and message id, doesnt appear in table 3, i am passing in th username, site, and MU_ID, in the query string as parameters.ThanksNo one ever said it was going to be easy, then again, nothing worth doing ever is.
i think thats exactly what i've given you.SELECT required columns....FROM Table1 t1INNER JOIN Table2 t2ON t.messageid=t2.messageidAND t2.username = @yourpassedusernameLEFT JOIN Table3 t3ON t3.messageid = t2.messageidAND t3.username = t3.usernameWHERE t3.messageid IS NULLAND t1.publishdate > = DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)AND t1.username = @UserAND site = @site and MU_ID = @MUID can you explain why you think its not working may be with some data example from tables------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|