Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i am using sqldependecy to get notify from sqlserver and use signalr for send alarm to some users that store in database

before that i sent alarm for all user and use simple select but now i want using complex select

What I have tried:

SELECT [CarrierFid], [pelacknumber], [Speed], [Timeoverspeed] FROM [dbo].[OverSpeedAlert]



I want to use the following select instead of the above select :

C#
var queries = new[]{ @"SELECT [CarrierFid], [pelacknumber], [Speed], [Timeoverspeed] FROM [dbo].[OverSpeedAlert] "+
                                     " WHERE visited = 0 AND  CONVERT(varchar(10), Timeoverspeed )= FORMAT(GETDATE(),'dd/MM/yyyy')  "+
                                      " and CarrierFid in ( "+
                                       " SELECT dbo.AlarmsCarrier.carrierFid "+
                                               " FROM dbo.AlarmsCarrier INNER JOIN  "+
                                                    " dbo.AlarmUsers ON dbo.AlarmsCarrier.AlarmCarrierid = dbo.AlarmUsers.AlarmCarrierFid INNER JOIN "+
                                                      " dbo.Users ON dbo.AlarmUsers.UserFid = dbo.Users.ID "+
                                                          " WHERE (dbo.Users.UserName = '"+ username +"'))" };
Posted
Updated 12-May-20 1:46am
Comments
mohamad_ali 12-May-20 7:22am    
thnx, ok I will change it

1 solution

That query cannot be used with a SqlDependency:
Query notifications are supported for SELECT statements that meet the following requirements:

The statement must not contain subqueries…

The statement must not use any nondeterministic functions…
Your In clause uses a subquery, and GETDATE is nondeterministic.
 
Share this answer
 
Comments
mohamad_ali 12-May-20 7:25am    
What solution do you suggest for this problem? i should send alarm to particular users and i should used inner join between some table
Richard Deeming 12-May-20 7:34am    
Set up a notification on a simpler query - for example:
SELECT dbo.AlarmsCarrier.carrierFid, dbo.AlarmUsers.UserFid
FROM dbo.AlarmsCarrier INNER JOIN dbo.AlarmUsers 
ON dbo.AlarmsCarrier.AlarmCarrierid = dbo.AlarmUsers.AlarmCarrierFid


That will notify you when an alarm is added or changed.

You can then run your query to find the alarms that you need to send.
mohamad_ali 12-May-20 7:50am    
i used getdate for display today's messages if i removed this condition After a few days, many messages will be displayed
Richard Deeming 12-May-20 7:51am    
As I said, use the notification to tell you when the alarms change. Then use your original query to find the alarms which need to be displayed.
Maciej Los 12-May-20 7:51am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900