Solved

SQl Display Query

Posted on 2012-03-29
6
310 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

777 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