Solved

SQl Display Query

Posted on 2012-03-29
6
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 60

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 60

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
Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

 

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 60

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

718 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