Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.sqlserver.programming > #31331
| X-Received | by 10.233.232.135 with SMTP id a129mr13726296qkg.14.1508848709732; Tue, 24 Oct 2017 05:38:29 -0700 (PDT) |
|---|---|
| X-Received | by 10.31.137.138 with SMTP id l132mr1214921vkd.14.1508848709700; Tue, 24 Oct 2017 05:38:29 -0700 (PDT) |
| Path | csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!z50no1498552qtj.0!news-out.google.com!v14ni16qtc.0!nntp.google.com!k31no1494819qta.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | microsoft.public.sqlserver.programming |
| Date | Tue, 24 Oct 2017 05:38:29 -0700 (PDT) |
| In-Reply-To | <XnsA817F2C2824FCYazorman@127.0.0.1> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=216.234.125.194; posting-account=4nS5WwoAAACio8l9etd0ayIsc32V0GtK |
| NNTP-Posting-Host | 216.234.125.194 |
| References | <d0c629ca-5826-4cd4-baba-9848a915df19@googlegroups.com> <XnsA817F2C2824FCYazorman@127.0.0.1> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <9ebb76da-7445-4b19-a786-49e159c79594@googlegroups.com> (permalink) |
| Subject | Re: How to add a datetime column for a 24 hour period |
| From | Mike Arney <mikespcnet.net@gmail.com> |
| Injection-Date | Tue, 24 Oct 2017 12:38:29 +0000 |
| Content-Type | text/plain; charset="UTF-8" |
| Lines | 112 |
| Xref | csiph.com microsoft.public.sqlserver.programming:31331 |
Show key headers only | View raw
On Monday, October 23, 2017 at 5:51:54 PM UTC-4, Erland Sommarskog wrote:
> Mike Arney (mikespcnet.net@gmail.com) writes:
> > I have a MSSQL table with the following columns and data types:
> >
> > Topic -- nvarchar
> > Payload -- numeric
> > Timestamp -- datetime
> > id -- int
> >
> >
> > Here is some example data:
> >
> > Topic Payload Timestamp id
> > STG/A/CycleStart 0 2017-10-23 15:37:56.697 1651
> > STG/A/CycleStart 0 2017-10-23 15:37:55.670 1650
> > STG/A/CycleStart 0 2017-10-23 15:37:55.193 1649
> > STG/A/CycleStart 0 2017-10-23 15:37:54.687 1648
> >
> >
> >
> > The Timestamp column's default value is set to: (getutcdate())
> >
> >
> > I need to add the TIMESTAMP column for the last 24 hours where TOPIC =
> > 'STG/A/CycleStart' and PAYLOAD = 1
> >
> > I also need this time in seconds.
> >
>
> Too bad then that the sample data only has payload = 0.
>
> The best way to get help with this type of question is to post
> 1) CREATE TABLE statements for your table(s), preferrably simplified
> to focus at the problem at hand.
> 2) INSERT statments with sample data.
> 3) The expected results given the sample.
> 4) A short description of the business rules that explains why you want
> that particular result.
> 5) Which version of SQL Server you are using.
>
> From the information you have posted so far, I am not prepare to make a
> guess about what you are looking for.
>
> --
> Erland Sommarskog, Stockholm, esquel@sommarskog.se
Sorry Erland,
I will try to explain better.
[code]
Create Table MQTTData(
Topic nvarchar(256),
Payload numeric(18,0),
Timestamp datetime Default GetUTCDate(),
id int Identity(1,1) Primary Key)
Insert Into MQTTData (Topic,Payload)
Values ('STG/A/CycleStart', 1)
WaitFor Delay '00:00:02'
Insert Into MQTTData (Topic,Payload)
Values ('STG/A/CycleStart', 0)
WaitFor Delay '00:00:02'
Insert Into MQTTData (Topic,Payload)
Values ('STG/A/CycleStart', 1)
WaitFor Delay '00:00:02'
Insert Into MQTTData (Topic,Payload)
Values ('STG/A/CycleStart', 0)
WaitFor Delay '00:00:02'
Insert Into MQTTData (Topic,Payload)
Values ('STG/A/CycleStart', 1)
WaitFor Delay '00:00:02'
Insert Into MQTTData (Topic,Payload)
Values ('STG/A/CycleStart', 0)
WaitFor Delay '00:00:02'
Insert Into MQTTData (Topic,Payload)
Values ('STG/A/CycleStart', 1)
[/code]
I need to SUM all Timestamp (in seconds) with a Topic of 'STG/A/CycleStart', a Payload of 1.
Payload of 1 = Machine On
Payload of 0 = Machine Off
I am trying to get amount of time that a Payload is = 1 over the last 24 hours.
Here is the sample data:
Topic Payload Timestamp id
STG/A/CycleStart 1 2017-10-24 12:00:37.160 1
STG/A/CycleStart 0 2017-10-24 12:00:39.160 2
STG/A/CycleStart 1 2017-10-24 12:00:41.160 3
STG/A/CycleStart 0 2017-10-24 12:00:43.160 4
STG/A/CycleStart 1 2017-10-24 12:00:45.163 5
STG/A/CycleStart 0 2017-10-24 12:00:47.167 6
STG/A/CycleStart 1 2017-10-24 12:00:49.167 7
I am using SQL 2014 Enterprise.
Thanks,
Mike
Back to microsoft.public.sqlserver.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to add a datetime column for a 24 hour period Mike Arney <mikespcnet.net@gmail.com> - 2017-10-23 11:42 -0700
Re: How to add a datetime column for a 24 hour period Erland Sommarskog <esquel@sommarskog.se> - 2017-10-23 23:51 +0200
Re: How to add a datetime column for a 24 hour period Mike Arney <mikespcnet.net@gmail.com> - 2017-10-24 05:10 -0700
Re: How to add a datetime column for a 24 hour period Mike Arney <mikespcnet.net@gmail.com> - 2017-10-24 05:12 -0700
Re: How to add a datetime column for a 24 hour period Mike Arney <mikespcnet.net@gmail.com> - 2017-10-24 05:38 -0700
Re: How to add a datetime column for a 24 hour period Erland Sommarskog <esquel@sommarskog.se> - 2017-10-24 20:49 +0200
Re: How to add a datetime column for a 24 hour period Mike Arney <mikespcnet.net@gmail.com> - 2017-10-25 04:57 -0700
Re: How to add a datetime column for a 24 hour period Erland Sommarskog <esquel@sommarskog.se> - 2017-10-26 20:58 +0200
Re: How to add a datetime column for a 24 hour period Mike Arney <mikespcnet.net@gmail.com> - 2017-11-02 09:54 -0700
Re: How to add a datetime column for a 24 hour period mikespcnet.net@gmail.com - 2018-05-08 08:21 -0700
Re: How to add a datetime column for a 24 hour period Mike Arney <mikespcnet.net@gmail.com> - 2018-05-08 08:35 -0700
Re: How to add a datetime column for a 24 hour period Erland Sommarskog <esquel@sommarskog.se> - 2018-05-08 19:48 +0200
Re: How to add a datetime column for a 24 hour period Mike Arney <mikespcnet.net@gmail.com> - 2018-05-09 06:31 -0700
Re: How to add a datetime column for a 24 hour period Mike Arney <mikespcnet.net@gmail.com> - 2018-05-09 06:34 -0700
Re: How to add a datetime column for a 24 hour period Erland Sommarskog <esquel@sommarskog.se> - 2018-05-09 23:08 +0200
csiph-web