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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Reminder

Author  Topic 

t1g312
Posting Yak Master

148 Posts

Posted - 2004-10-26 : 06:47:57
Hi all,

I am working on a passenger management system in VB/Sql Server which stores information about passengers arrivals and departures. I have been asked to add a reminder feature which will alert the user 1 hour before a passenger's arrival/departure. I was thinking in the lines of running a stored procedure as a job (is it possible?) say every 30 mins and sending an email to the user. Is there a better way of doing it? Also, how can I make a message pop-up in the user's PC with the same reminder?

Thanks in advance!

Adi

-------------------------
/me sux @sql server

Kristen
Test

22859 Posts

Posted - 2004-10-26 : 08:22:33
If its a Web app you could have a little window with a META REFRESH that checks to see if there are "reminders" every minute. But it will only work if it is maximise (doesn't have to be the current window though)

For a Windows app you could have something which WILL run when minimised that does a SQL query every minute, say.

Or, as you say, you could run an EMailing task on the SQL box that sends Emails periodically. I would suggest running it more frequently than 30 minutes for a one hour reminder (10 minutes sounds about right) - someone might be registered 29 minutes before departure - does that need to cause a Reminder Email?

Keep in mind that EMail is not guaranteed-delivery - so once in a while the Email won't get to the recipient ...

For a really cheap&cheerful solution you could use ServersAlive and set it to run a SQL query every few minutes and to treat the query as FAILURE when there are items to be viewed - the user then has to view, and "cancel" the items, for the FAILURE to be cleared. ServersAlive can make a horrible noise on "failure" :-)

Maybe even better would be to use MSAgent - the text-to-speech animated thigie. That could go runnign all round the user's screen with all sorts of useful speech-balloons and voice-output messages ....

... maybe I'm getting a little carried away!

Kristen
Go to Top of Page

t1g312
Posting Yak Master

148 Posts

Posted - 2004-10-26 : 09:09:04
quote:
Originally posted by Kristen

If its a Web app you could have a little window with a META REFRESH that checks to see if there are "reminders" every minute. But it will only work if it is maximise (doesn't have to be the current window though)

For a Windows app you could have something which WILL run when minimised that does a SQL query every minute, say.

Or, as you say, you could run an EMailing task on the SQL box that sends Emails periodically. I would suggest running it more frequently than 30 minutes for a one hour reminder (10 minutes sounds about right) - someone might be registered 29 minutes before departure - does that need to cause a Reminder Email?

Keep in mind that EMail is not guaranteed-delivery - so once in a while the Email won't get to the recipient ...

For a really cheap&cheerful solution you could use ServersAlive and set it to run a SQL query every few minutes and to treat the query as FAILURE when there are items to be viewed - the user then has to view, and "cancel" the items, for the FAILURE to be cleared. ServersAlive can make a horrible noise on "failure" :-)

Maybe even better would be to use MSAgent - the text-to-speech animated thigie. That could go runnign all round the user's screen with all sorts of useful speech-balloons and voice-output messages ....

... maybe I'm getting a little carried away!

Kristen



Hold your horses! What about a sql query that sends out emails and network messages? It could be scheduled using the job scheduling feature.

One more question. I have a date field and a time field which contains the passenger's arrival/departure information. I was thinking of using the datediff fuction using these fields and the current time. The problem is that I don't know how to combine the date field and time field into one field so that i can compare it with the current time (getnow()). How do I go about it?

Thanks

Adi

-------------------------
/me sux @sql server
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-10-26 : 09:45:50
SELECT *
FROM MyTable
WHERE DATEDIFF(Minute, GetDate(), CONVERT(Datetime, MyDate + ' ' + MyTime)) <= 60

Your columns "MyDate" and "MyTime" will have to formatted in a style sympathetic to SQL, or you will need to use
SET DATEFORMAT DMY
to get SQL to recognise the order the date components are in

For unambiquous date/time, as a text string, you are best off with "yyyymmdd hh:mm:ss"

Do this to check that SQL is on the same wavelength as you:

SELECT TOP 10 CONVERT(Datetime, '01/02/04' + ' ' + '12:23')

where the bits in red are in the same format your data is stored in, and you use an ambiguous date - like my example "01/02/04".

A network message has merit - you can send that with something like

DECLARE @strCommand varchar(8000), @intRowCount int
SELECT @intRowCount = 1 -- Force first loop iteration
WHILE @intRowCount > 0
BEGIN
SELECT TOP 1 @strCommand = 'NET SEND ' + OperatorsName
+ ' "' + PasengerName + ' arrives at '
+ ArrivalTime + '"',
@MyID = MyID
FROM MyTable
WHERE ArrivalTime < DATEADD(Minute, 60, GetDate())
AND ArrivalAnnounced = 0
SELECT @intRowCount = @@ROWCOUNT
IF @intRowCount > 0 EXEC master.dbo.xp_cmdshell @strCommand
UPDATE U
SET ArrivalAnnounced = 1
FROM MyTable U
WHERE MyID = @MyID
END

Kristen
Go to Top of Page

t1g312
Posting Yak Master

148 Posts

Posted - 2004-10-27 : 02:14:14
Hi Kristen,
I get the error "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value." when I try the following:

declare @DateTime datetime
select @DateTime=convert(datetime,convert(varchar(10),DateField,103) + ' ' + convert(varchar(5), TimeField,108)) from MyTable where id=1


Adi

-------------------------
/me sux @sql server
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-10-27 : 04:02:37
You aint got your date in the right format for your server then, I'm afraid.

What does

SELECT TOP 10 CONVERT(Datetime, '01/02/04' + ' ' + '12:23')

give you?

On our box I get

2004-01-02 12:23:00.000

so that means that my date format is mm/dd/yyyy

if I then do

SELECT 'SELECT convert(datetime,''' + convert(varchar(10),GetDate(),103) + ' ' + convert(varchar(5), GetDate(),108) + ''')'

(to see what data is going to be presented) I get:

SELECT convert(datetime,'27/10/2004 08:55')

which is clearly dd/mm/yyyy - so that aint gonna work!

However, looks like your Date and Time are already in datetime datatype columns, so there is no point converting them to text for this operation. (From your original desciprtion I had assumed they were in text columns). So what you need is something which takes the DATE part of the DateField and the TIME part of the TimeField and joins them together. Lets just make an experiment:

-- Get just date
SELECT DATEADD(Day, DATEDIFF(Day, 0, GetDate()), 0)

-- Get just time
SELECT GetDate() - DATEADD(Day, DATEDIFF(Day, 0, GetDate()), 0)

-- Both together
SELECT DATEADD(Day, DATEDIFF(Day, 0, GetDate()), 0)
+ (GetDate() - DATEADD(Day, DATEDIFF(Day, 0, GetDate()), 0))

so what you need is

SELECT DATEADD(Day, DATEDIFF(Day, 0, DateField), 0)
+ (TimeField - DATEADD(Day, DATEDIFF(Day, 0, TimeField), 0))

however if your DateField has no time element (i.e. they are all
"dd/mm/yyyy 00:00:00.000") and you TimeField contains just time (i.e. they are all
"1900-01-01 hh:mm:ss.nnn") then you could just do

SELECT (DateField + TimeField)

Kristen
Go to Top of Page

t1g312
Posting Yak Master

148 Posts

Posted - 2004-10-31 : 06:19:07
I wrote a script that send out net send messages and emails. When I execute it as a job using Agent, only the email works but I don't see any pop up messages. Why is this happening?

Thanks

Adi

-------------------------
/me sux @sql server
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-11-01 : 21:46:21
net send is probably restricted, what's your script for net send?

--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -