Solved

SQl Display Query

Posted on 2012-03-29
6
308 Views
Last Modified: 2012-04-03
Hi

I have been tasked with the following, We have alot of visitors visiting our company and the company would like some for of Welcome to display on a screen in reception, so what i am doing is collecting data from our CRM software which i will then display onto the monitor.

The query looks like this at the moment

SELECT     dbo.dmactiv.startdate, dbo.dmactiv.starttime, dbo.dmactiv.duration, dbo.dmcont.firstname, dbo.dmcont.lastname, dbo.dmcont.comp_name
FROM         dbo.dmactiv INNER JOIN
                      dbo.dmcont ON dbo.dmactiv.contid = dbo.dmcont.contid

and this output something along the lines of this

Startdate             StartTime         Duration      Firstname     LastName          Comp_Name

2012-04-18                780                    60                joe                bloggs             microsoft


so i deally what i would like to do is half an hour before the arrival the query returns only those that are visiting and once the duration has ended then they no longer are part of the query.


However as you can see from the above data the start Time and duration are produced as whole numbers and i am not sure how to acheive this

Can anybody help

John

Ps sorry for not posting the code properly but all the body functions always seem to be greyed out and i can never add anything not sure why :(
0
Comment
Question by:pepps11976
  • 3
  • 3
6 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 37782372
What do the whole numbers represent (e.g., minutes)?
0
 

Author Comment

by:pepps11976
ID: 37782444
yes that particular example that i posted above its start time is 13.00 so 780 mins is what it is representing

John
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 37782466
If it is in minutes, then here is an example of what I may do.
First, the main idea is to generate a start and end DATETIME value from the three columns you have listed.

e.g.,

DECLARE @StartDate DATE = '2012-04-18', @StartTime INT = 780, @Duration INT = 60;
SELECT StartTime = DATEADD(MINUTE, @StartTime-30, CONVERT(DATETIME, @StartDate))
     , EndTime = DATEADD(MINUTE, @StartTime+@Duration, CONVERT(DATETIME, @StartDate))
;

StartTime               EndTime
----------------------- -----------------------
2012-04-18 12:30:00.000 2012-04-18 14:00:00.000

Open in new window


Note: I subtracted 30 minutes to account for the "half an hour before the arrival" portion of the requirement. Without this, you would get the actual start time, which I believe is 1PM.

Putting this together with your query:

SELECT dbo.dmactiv.startdate, dbo.dmactiv.starttime, dbo.dmactiv.duration
     , dbo.dmcont.firstname, dbo.dmcont.lastname, dbo.dmcont.comp_name
FROM dbo.dmactiv
INNER JOIN dbo.dmcont ON dbo.dmactiv.contid = dbo.dmcont.contid
WHERE CURRENT_TIMESTAMP BETWEEN DATEADD(MINUTE, dbo.dmactiv.starttime-30, CONVERT(DATETIME, dbo.dmactiv.startdate)) AND DATEADD(MINUTE, dbo.dmactiv.starttime+dbo.dmactiv.duration, CONVERT(DATETIME, dbo.dmactiv.startdate))
;

I hope that helps!
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:pepps11976
ID: 37782490
Thats great

i assume with what you posted it gets rid of visits that have gone past there time etc?
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 37782510
Yes, once the current timestamp greater than the end time of the appointment, the record will no longer show (tested). So, if there query is scheduled it should pick up new visitors and drop off old ones automatically.
0
 

Author Comment

by:pepps11976
ID: 37782543
Superb Thanks for your help
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now