Showing posts with label blocked. Show all posts
Showing posts with label blocked. Show all posts

Monday, March 26, 2012

help on query

I need to select all messages for user X from all users, except those who user X has blocked in tblBlockList.
I have the following query, but it returns a row for each time UserCodeBlocked is not equal to UserCodeSender...

What I need is just to select all messages for a user EXCEPT when they are from a user in the blocklist...
I have tried the keyworddistinct but that ofcourse doesnt work since Row_number makes every row unique...
tblMessages contains the actual message
tblUsersandmessages relates users and messages

select ROW_NUMBER() OVER (ORDER BY a.SentDateTime DESC) as RowNum,a.MessageID,a.UserCodeSender,a.MessageTitle,a.SentDateTime
FROM tblMessages a
INNER JOIN tblUsersAndMessages b ON (a.MessageID=b.MessageID)
INNER JOIN tblUserData c ON (a.UserCodeSender=c.UserCode)
RIGHT JOIN tblBlockList bl ON bl.UserCodeBlocked<>a.UserCodeSender
WHERE b.UserCode=5

did you try a left join instead of a right join? You want the data for the message, not for the block list.

select ROW_NUMBER()OVER (ORDER BY a.SentDateTimeDESC)as RowNum,a.MessageID,a.UserCodeSender,a.MessageTitle,a.SentDateTimeFROM tblMessages aINNERJOIN tblUsersAndMessages bON (a.MessageID=b.MessageID)INNERJOIN tblUserData cON (a.UserCodeSender=c.UserCode)LEFTOUTER JOIN tblBlockList blON bl.UserCodeBlocked<>a.UserCodeSenderWHERE b.UserCode=5

If this doesn't help, please post the table structures and/or relationship diagram

|||tblBlockList
UserCodeBlocker int 'person who has blocked someone
UserCodeBlocked int 'person being blocked

tblMessages
UserCodeSender int
MessageID int
MessageTitle
...

tblUsersAndMessages
UserCode int
MessageID int
...sql

Monday, February 27, 2012

help me! my mssql 2000 server (with sp3a) is keeping full loading my cpu non-stop now!

my mssql never be used much
and i had a firewall to blocked the port of mssql to internet

but i don't that why tonight the sql server non-stop keep full loading the cpu suddenly until now!
please help meSQL Server 2000 SP3a is nothing but 10.5 megs of Transact code, if you send me an email with the in my profile I can help you with it. That is some of the most clean and close to ANSI SQL code I have seen from Microsoft. You may want to ignore some of the questions Windows ask you answer only those relevant to you. I write ANSI SQL, Transact-SQL, Java and C#. Hope this help.

Kind regards,
Gift Peddie|||do u have any msn messenger then?|||No I don't do messengers, what I can tell you is there are 25 files and Windows will only execute the files applicable to you because only 11 files were executed on my Windows 2003 Enterprise Server that was not part of a network. But with SP3a I was able to install Reporting Services and Analysis Services without problem and I had Visual Studio 2003 on the box before SP3a. Hope this help.

Kind regards,
Gift Peddie