Showing posts with label seconds. Show all posts
Showing posts with label seconds. Show all posts

Monday, March 12, 2012

Help with query

Let me preface this by saying that am relatively new to SQL.
I have a database that is updated every10 to 15 seconds with broadcasts
from our customer. These broadcasts come from 2 distinct points in
their operation. The first point - 39 - tells me what to build and
ship to them. The second point - 105 - tells me when they have used my
product on the line. Every thing is controlled by a serial number.
So, for example, at 8 AM they will send a broadcast saying that serial
number 1234 is at point 39 (my cue to build and ship the part), then
about 3 hours later I will get a broadcast from point 105 that serial
number 1234 has been built (my cue that my parts have been consumed).
In the intervening 3 hours, there will have been a bunch of broadcasts
through each point. Each broadcast is writted to a single table with
the following fields:
ProcessDate - The date/time stamp that the broadcast was received
SerialNumber - The serial number referenced by the broadcast
ReportingPoint - The point that generated the broadcast (either 39 or
105)
OK, so here is the query I want to build:
Whenever the query is run, it should find the serial number of most
current broadcast from 105. Then it should use that serial number to
find out the date/time that unit passed through 39. Then it should
return a list of everything that has passed through 39 between that
time and the current time.
If you need more info, or if this isn't clear, please ask. I don't
even know where to get started on this one.
Thanks!
TimThe way to approach these is to write it a little bit at a time,
building it up.
>Whenever the query is run, it should find the serial number of most
>current broadcast from 105.
SELECT TOP 1 ProcessDate, SerialNumber
FROM Whatever
WHERE ReportingPoint = 105
ORDER BY ProcessDate
>Then it should use that serial number to
>find out the date/time that unit passed through 39.
SELECT ProcessDate
FROM Whatever as W
JOIN (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate) as X
ON W.SerialNumber = X.SerialNumber
WHERE W.ReportingPoint = 39
>Then it should
>return a list of everything that has passed through 39 between that
>time and the current time.
SELECT *
FROM Whatever as A
WHERE ReportingPoint = 39
AND ProcessDate >= (select ProcessDate
from Whatever as W
join (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate) as X
on W.SerialNumber = X.SerialNumber)
All untested, of course.
Roy Harvey
Beacon Falls, CT
On 25 Jul 2006 08:21:33 -0700, Timothy.Rybak@.gmail.com wrote:
>Let me preface this by saying that am relatively new to SQL.
>I have a database that is updated every10 to 15 seconds with broadcasts
>from our customer. These broadcasts come from 2 distinct points in
>their operation. The first point - 39 - tells me what to build and
>ship to them. The second point - 105 - tells me when they have used my
>product on the line. Every thing is controlled by a serial number.
>So, for example, at 8 AM they will send a broadcast saying that serial
>number 1234 is at point 39 (my cue to build and ship the part), then
>about 3 hours later I will get a broadcast from point 105 that serial
>number 1234 has been built (my cue that my parts have been consumed).
>In the intervening 3 hours, there will have been a bunch of broadcasts
>through each point. Each broadcast is writted to a single table with
>the following fields:
>ProcessDate - The date/time stamp that the broadcast was received
>SerialNumber - The serial number referenced by the broadcast
>ReportingPoint - The point that generated the broadcast (either 39 or
>105)
>OK, so here is the query I want to build:
>Whenever the query is run, it should find the serial number of most
>current broadcast from 105. Then it should use that serial number to
>find out the date/time that unit passed through 39. Then it should
>return a list of everything that has passed through 39 between that
>time and the current time.
>If you need more info, or if this isn't clear, please ask. I don't
>even know where to get started on this one.
>Thanks!
>Tim|||Please excuse my ignorance.
When I run the first part of the query, the TOP 1 is returning the
earliest instance of the 105 broadcast point in the table, instead of
the most recent entry. Is this correct, or am I doing something wrong
already?
The ProcessDate column is in the standard 'mm/dd/yyyy hh:mm:ss AM/PM'
format.
Roy Harvey wrote:
> The way to approach these is to write it a little bit at a time,
> building it up.
> >Whenever the query is run, it should find the serial number of most
> >current broadcast from 105.
> SELECT TOP 1 ProcessDate, SerialNumber
> FROM Whatever
> WHERE ReportingPoint = 105
> ORDER BY ProcessDate
> >Then it should use that serial number to
> >find out the date/time that unit passed through 39.
> SELECT ProcessDate
> FROM Whatever as W
> JOIN (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate) as X
> ON W.SerialNumber = X.SerialNumber
> WHERE W.ReportingPoint = 39
> >Then it should
> >return a list of everything that has passed through 39 between that
> >time and the current time.
>
> SELECT *
> FROM Whatever as A
> WHERE ReportingPoint = 39
> AND ProcessDate >=> (select ProcessDate
> from Whatever as W
> join (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate) as X
> on W.SerialNumber = X.SerialNumber)
> All untested, of course.
> Roy Harvey
> Beacon Falls, CT
> On 25 Jul 2006 08:21:33 -0700, Timothy.Rybak@.gmail.com wrote:
> >Let me preface this by saying that am relatively new to SQL.
> >
> >I have a database that is updated every10 to 15 seconds with broadcasts
> >from our customer. These broadcasts come from 2 distinct points in
> >their operation. The first point - 39 - tells me what to build and
> >ship to them. The second point - 105 - tells me when they have used my
> >product on the line. Every thing is controlled by a serial number.
> >So, for example, at 8 AM they will send a broadcast saying that serial
> >number 1234 is at point 39 (my cue to build and ship the part), then
> >about 3 hours later I will get a broadcast from point 105 that serial
> >number 1234 has been built (my cue that my parts have been consumed).
> >In the intervening 3 hours, there will have been a bunch of broadcasts
> >through each point. Each broadcast is writted to a single table with
> >the following fields:
> >
> >ProcessDate - The date/time stamp that the broadcast was received
> >SerialNumber - The serial number referenced by the broadcast
> >ReportingPoint - The point that generated the broadcast (either 39 or
> >105)
> >
> >OK, so here is the query I want to build:
> >
> >Whenever the query is run, it should find the serial number of most
> >current broadcast from 105. Then it should use that serial number to
> >find out the date/time that unit passed through 39. Then it should
> >return a list of everything that has passed through 39 between that
> >time and the current time.
> >
> >If you need more info, or if this isn't clear, please ask. I don't
> >even know where to get started on this one.
> >
> >Thanks!
> >Tim|||On 25 Jul 2006 09:45:42 -0700, Timothy.Rybak@.gmail.com wrote:
>Please excuse my ignorance.
>When I run the first part of the query, the TOP 1 is returning the
>earliest instance of the 105 broadcast point in the table, instead of
>the most recent entry. Is this correct, or am I doing something wrong
>already?
Simple explanation: I left off the DESC on the ORDER BY.
SELECT TOP 1 ProcessDate, SerialNumber
FROM Whatever
WHERE ReportingPoint = 105
ORDER BY ProcessDate DESC
>Then it should use that serial number to
>find out the date/time that unit passed through 39.
SELECT ProcessDate
FROM Whatever as W
JOIN (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate DESC) as X
ON W.SerialNumber = X.SerialNumber
WHERE W.ReportingPoint = 39
>Then it should
>return a list of everything that has passed through 39 between that
>time and the current time.
SELECT *
FROM Whatever as A
WHERE ReportingPoint = 39
AND ProcessDate >= (select ProcessDate
from Whatever as W
join (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate DESC) as X
on W.SerialNumber = X.SerialNumber)
Roy|||This has been a great help! I have gotten the first two parts to work.
The last part is still giving me problems. Here is how SQL is
interpreting the code:
SELECT *
FROM [Whatever]
WHERE (ReportingPoint = '39') AND (ProcessDate >= (SELECT W.ProcessDate, W.SerialNumber
FROM [Whatever] W INNER JOIN
(SELECT TOP 1 ProcessDate, SerialNumber
FROM [Whatever]
WHERE (ReportingPoint = 'D05')
ORDER BY ProcessDate DESC) X ON W.SerialNumber =X.SerialNumber))
It is giving me the following error:
"Only one expression can be specified in the select list when the
subquery is not introducted with EXISTS"
While I understand the theory of what you wrote, I don't have the
knowledge to fix the issue.
Can you help?
Tim
Roy Harvey wrote:
> On 25 Jul 2006 09:45:42 -0700, Timothy.Rybak@.gmail.com wrote:
> >Please excuse my ignorance.
> >
> >When I run the first part of the query, the TOP 1 is returning the
> >earliest instance of the 105 broadcast point in the table, instead of
> >the most recent entry. Is this correct, or am I doing something wrong
> >already?
> Simple explanation: I left off the DESC on the ORDER BY.
> SELECT TOP 1 ProcessDate, SerialNumber
> FROM Whatever
> WHERE ReportingPoint = 105
> ORDER BY ProcessDate DESC
> >Then it should use that serial number to
> >find out the date/time that unit passed through 39.
> SELECT ProcessDate
> FROM Whatever as W
> JOIN (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate DESC) as X
> ON W.SerialNumber = X.SerialNumber
> WHERE W.ReportingPoint = 39
> >Then it should
> >return a list of everything that has passed through 39 between that
> >time and the current time.
>
> SELECT *
> FROM Whatever as A
> WHERE ReportingPoint = 39
> AND ProcessDate >=> (select ProcessDate
> from Whatever as W
> join (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate DESC) as X
> on W.SerialNumber = X.SerialNumber)
> Roy|||On 25 Jul 2006 10:43:27 -0700, Timothy.Rybak@.gmail.com wrote:
>This has been a great help! I have gotten the first two parts to work.
> The last part is still giving me problems.
Sorry, I just have been asleep. Lots of problems, which I think I
have fixed.
create table Whatever
(ProcessDate datetime, -- The date/time stamp that the broadcast was
received
SerialNumber int, -- The serial number referenced by the broadcast
ReportingPoint int) -- The point that generated the broadcast (either
39 or 105)
INSERT Whatever values('1 Jan 2002 00:00', 123, 39)
INSERT Whatever values('1 Jan 2002 01:00', 456, 39)
INSERT Whatever values('1 Jan 2002 02:00', 789, 39)
INSERT Whatever values('1 Jan 2002 03:00', 368, 39)
INSERT Whatever values('1 Jan 2002 04:00', 246, 39)
INSERT Whatever values('1 Jan 2002 05:00', 468, 39)
INSERT Whatever values('1 Jan 2002 04:30', 123, 105)
INSERT Whatever values('1 Jan 2002 06:00', 456, 105)
-->Whenever the query is run, it should find the serial number of most
-->current broadcast from 105.
SELECT TOP 1 ProcessDate, SerialNumber
FROM Whatever
WHERE ReportingPoint = 105
ORDER BY ProcessDate DESC
ProcessDate SerialNumber
--- --
2002-01-01 06:00:00.000 456
-->Then it should use that serial number to
-->find out the date/time that unit passed through 39.
SELECT max(W.ProcessDate)
FROM Whatever as W
JOIN (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate DESC) as X
ON W.SerialNumber = X.SerialNumber
AND W.ProcessDate < X.ProcessDate
WHERE W.ReportingPoint = 39
---
2002-01-01 01:00:00.000
-->Then it should
-->return a list of everything that has passed through 39 between that
-->time and the current time.
SELECT *
FROM Whatever as A
WHERE ReportingPoint = 39
AND ProcessDate >= (select W.ProcessDate
from Whatever as W
join (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate DESC) as X
on W.SerialNumber = X.SerialNumber
and W.ProcessDate < X.ProcessDate
where W.ReportingPoint = 39)
ProcessDate SerialNumber
ReportingPoint
--- --
--
2002-01-01 01:00:00.000 456 39
2002-01-01 02:00:00.000 789 39
2002-01-01 03:00:00.000 368 39
2002-01-01 04:00:00.000 246 39
2002-01-01 05:00:00.000 468 39
Roy|||Ok, I figured out, I think, that I can't have two values in the second
Select statement, or else the compison won't work - ProcessDate>= must
return a date, and a date only.
So, I fixed that. Now, I have the following:
SELECT *
FROM [Whatever] A
WHERE (ReportingPoint = '39') AND (ProcessDate >= (SELECT W.ProcessDate
FROM [Whatever] W INNER JOIN
(SELECT TOP 1 ProcessDate,
SerialNumber
FROM [Whatever]
WHERE ReportingPoint = '105'
ORDER BY ProcessDate DESC) X ON
W.SerialNumber = X.SerialNumber))
I am getting this error now:
Subquery returned more than one value. This is not permitted when the
subquery follows =, !=, <, <=, >, >= or when the subquery is used as an
expression.
Any help?
Thanks!
Tim|||We must have posted at the same time.
Your new query is PERFECT!
Thank you so much for your patience, time, and effort!
Tim|||Ok, I got this to work, and everyone was happy.
Now, they want to be able to do this, but they want to be able to pick
the moment in time, rather than just using the most up to date data.
So, I tried to modify the code as follows, but I get the error: Must
Declare the variable @.GetDate
I don't want to declare it, I want the user to have to enter it. Any
ideas?
SELECT *
FROM Whatever as A
WHERE ReportingPoint = 39
AND ProcessDate >= (select W.ProcessDate
from Whatever as W
join (select ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
and ProcessDate >= @.GetDate
order by ProcessDate DESC) as X
on W.SerialNumber = X.SerialNumber
and W.ProcessDate < X.ProcessDate
where W.ReportingPoint = 39)
INSERT Whatever values('1 Jan 2002 04:00', 246, 39)
> INSERT Whatever values('1 Jan 2002 05:00', 468, 39)
> INSERT Whatever values('1 Jan 2002 04:30', 123, 105)
> INSERT Whatever values('1 Jan 2002 06:00', 456, 105)
>
> -->Whenever the query is run, it should find the serial number of most
> -->current broadcast from 105.
> SELECT TOP 1 ProcessDate, SerialNumber
> FROM Whatever
> WHERE ReportingPoint = 105
> ORDER BY ProcessDate DESC
> ProcessDate SerialNumber
> --- --
> 2002-01-01 06:00:00.000 456
> -->Then it should use that serial number to
> -->find out the date/time that unit passed through 39.
> SELECT max(W.ProcessDate)
> FROM Whatever as W
> JOIN (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate DESC) as X
> ON W.SerialNumber = X.SerialNumber
> AND W.ProcessDate < X.ProcessDate
> WHERE W.ReportingPoint = 39
> ---
> 2002-01-01 01:00:00.000
> -->Then it should
> -->return a list of everything that has passed through 39 between that
> -->time and the current time.
>
> SELECT *
> FROM Whatever as A
> WHERE ReportingPoint = 39
> AND ProcessDate >=> (select W.ProcessDate
> from Whatever as W
> join (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate DESC) as X
> on W.SerialNumber = X.SerialNumber
> and W.ProcessDate < X.ProcessDate
> where W.ReportingPoint = 39)
> ProcessDate SerialNumber
> ReportingPoint
> --- --
> --
> 2002-01-01 01:00:00.000 456 39
> 2002-01-01 02:00:00.000 789 39
> 2002-01-01 03:00:00.000 368 39
> 2002-01-01 04:00:00.000 246 39
> 2002-01-01 05:00:00.000 468 39
> Roy|||What are the users using to run the query? A front-end application?
Query Analyzer? SQL Server has NO provision for prompting for input.
Perhaps the answer is to put it all in a stored procedure and pass
@.DateLimit as a parameter. Then, whatever the front end is, EXEC the
proc with the date (in single quotes) as a parameter.
Roy Harvey
Beacon Falls, CT
On 3 Aug 2006 12:24:59 -0700, Timothy.Rybak@.gmail.com wrote:
>Ok, I got this to work, and everyone was happy.
>Now, they want to be able to do this, but they want to be able to pick
>the moment in time, rather than just using the most up to date data.
>So, I tried to modify the code as follows, but I get the error: Must
>Declare the variable @.GetDate
>I don't want to declare it, I want the user to have to enter it. Any
>ideas?
>SELECT *
> FROM Whatever as A
> WHERE ReportingPoint = 39
> AND ProcessDate >=> (select W.ProcessDate
> from Whatever as W
> join (select ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> and ProcessDate >= @.GetDate
> order by ProcessDate DESC) as X
> on W.SerialNumber = X.SerialNumber
> and W.ProcessDate < X.ProcessDate
> where W.ReportingPoint = 39)
>
>
>INSERT Whatever values('1 Jan 2002 04:00', 246, 39)
>> INSERT Whatever values('1 Jan 2002 05:00', 468, 39)
>> INSERT Whatever values('1 Jan 2002 04:30', 123, 105)
>> INSERT Whatever values('1 Jan 2002 06:00', 456, 105)
>>
>> -->Whenever the query is run, it should find the serial number of most
>> -->current broadcast from 105.
>> SELECT TOP 1 ProcessDate, SerialNumber
>> FROM Whatever
>> WHERE ReportingPoint = 105
>> ORDER BY ProcessDate DESC
>> ProcessDate SerialNumber
>> --- --
>> 2002-01-01 06:00:00.000 456
>> -->Then it should use that serial number to
>> -->find out the date/time that unit passed through 39.
>> SELECT max(W.ProcessDate)
>> FROM Whatever as W
>> JOIN (select TOP 1 ProcessDate, SerialNumber
>> from Whatever
>> where ReportingPoint = 105
>> order by ProcessDate DESC) as X
>> ON W.SerialNumber = X.SerialNumber
>> AND W.ProcessDate < X.ProcessDate
>> WHERE W.ReportingPoint = 39
>> ---
>> 2002-01-01 01:00:00.000
>> -->Then it should
>> -->return a list of everything that has passed through 39 between that
>> -->time and the current time.
>>
>> SELECT *
>> FROM Whatever as A
>> WHERE ReportingPoint = 39
>> AND ProcessDate >=>> (select W.ProcessDate
>> from Whatever as W
>> join (select TOP 1 ProcessDate, SerialNumber
>> from Whatever
>> where ReportingPoint = 105
>> order by ProcessDate DESC) as X
>> on W.SerialNumber = X.SerialNumber
>> and W.ProcessDate < X.ProcessDate
>> where W.ReportingPoint = 39)
>> ProcessDate SerialNumber
>> ReportingPoint
>> --- --
>> --
>> 2002-01-01 01:00:00.000 456 39
>> 2002-01-01 02:00:00.000 789 39
>> 2002-01-01 03:00:00.000 368 39
>> 2002-01-01 04:00:00.000 246 39
>> 2002-01-01 05:00:00.000 468 39
>> Roy|||Sorry, I should have stipulated. The query will drive a report
generated by Reporting Services. I like to get the queries working in
the analyzer or enterprise manager first, before wasting time
developing a report to handle the results.
I've never worked with stored procedures before... I'm pretty new to
sql.
Thanks!
TIm
Roy Harvey wrote:
> What are the users using to run the query? A front-end application?
> Query Analyzer? SQL Server has NO provision for prompting for input.
> Perhaps the answer is to put it all in a stored procedure and pass
> @.DateLimit as a parameter. Then, whatever the front end is, EXEC the
> proc with the date (in single quotes) as a parameter.
> Roy Harvey
> Beacon Falls, CT
> On 3 Aug 2006 12:24:59 -0700, Timothy.Rybak@.gmail.com wrote:
> >Ok, I got this to work, and everyone was happy.
> >
> >Now, they want to be able to do this, but they want to be able to pick
> >the moment in time, rather than just using the most up to date data.
> >So, I tried to modify the code as follows, but I get the error: Must
> >Declare the variable @.GetDate
> >
> >I don't want to declare it, I want the user to have to enter it. Any
> >ideas?
> >
> >SELECT *
> > FROM Whatever as A
> > WHERE ReportingPoint = 39
> > AND ProcessDate >=> > (select W.ProcessDate
> > from Whatever as W
> > join (select ProcessDate, SerialNumber
> > from Whatever
> > where ReportingPoint = 105
> > and ProcessDate >= @.GetDate
> > order by ProcessDate DESC) as X
> > on W.SerialNumber = X.SerialNumber
> > and W.ProcessDate < X.ProcessDate
> > where W.ReportingPoint = 39)
> >
> >
> >
> >
> >INSERT Whatever values('1 Jan 2002 04:00', 246, 39)
> >> INSERT Whatever values('1 Jan 2002 05:00', 468, 39)
> >>
> >> INSERT Whatever values('1 Jan 2002 04:30', 123, 105)
> >> INSERT Whatever values('1 Jan 2002 06:00', 456, 105)
> >>
> >>
> >> -->Whenever the query is run, it should find the serial number of most
> >> -->current broadcast from 105.
> >>
> >> SELECT TOP 1 ProcessDate, SerialNumber
> >> FROM Whatever
> >> WHERE ReportingPoint = 105
> >> ORDER BY ProcessDate DESC
> >>
> >> ProcessDate SerialNumber
> >> --- --
> >> 2002-01-01 06:00:00.000 456
> >>
> >> -->Then it should use that serial number to
> >> -->find out the date/time that unit passed through 39.
> >>
> >> SELECT max(W.ProcessDate)
> >> FROM Whatever as W
> >> JOIN (select TOP 1 ProcessDate, SerialNumber
> >> from Whatever
> >> where ReportingPoint = 105
> >> order by ProcessDate DESC) as X
> >> ON W.SerialNumber = X.SerialNumber
> >> AND W.ProcessDate < X.ProcessDate
> >> WHERE W.ReportingPoint = 39
> >>
> >> ---
> >> 2002-01-01 01:00:00.000
> >>
> >> -->Then it should
> >> -->return a list of everything that has passed through 39 between that
> >> -->time and the current time.
> >>
> >>
> >> SELECT *
> >> FROM Whatever as A
> >> WHERE ReportingPoint = 39
> >> AND ProcessDate >=> >> (select W.ProcessDate
> >> from Whatever as W
> >> join (select TOP 1 ProcessDate, SerialNumber
> >> from Whatever
> >> where ReportingPoint = 105
> >> order by ProcessDate DESC) as X
> >> on W.SerialNumber = X.SerialNumber
> >> and W.ProcessDate < X.ProcessDate
> >> where W.ReportingPoint = 39)
> >>
> >> ProcessDate SerialNumber
> >> ReportingPoint
> >> --- --
> >> --
> >> 2002-01-01 01:00:00.000 456 39
> >> 2002-01-01 02:00:00.000 789 39
> >> 2002-01-01 03:00:00.000 368 39
> >> 2002-01-01 04:00:00.000 246 39
> >> 2002-01-01 05:00:00.000 468 39
> >>
> >> Roy|||On 3 Aug 2006 17:38:19 -0700, Timothy.Rybak@.gmail.com wrote:
>Sorry, I should have stipulated. The query will drive a report
>generated by Reporting Services. I like to get the queries working in
>the analyzer or enterprise manager first, before wasting time
>developing a report to handle the results.
>I've never worked with stored procedures before... I'm pretty new to
>sql.
>Thanks!
>TIm
I've never worked with Reporting Services, so I guess that makes us
even. I would assume that RS provides some means for a user to
provide parameters, but I can't help you with it. I RS works with
stored procedures.
Roy

Friday, March 9, 2012

Help with query

Let me preface this by saying that am relatively new to SQL.
I have a database that is updated every10 to 15 seconds with broadcasts
from our customer. These broadcasts come from 2 distinct points in
their operation. The first point - 39 - tells me what to build and
ship to them. The second point - 105 - tells me when they have used my
product on the line. Every thing is controlled by a serial number.
So, for example, at 8 AM they will send a broadcast saying that serial
number 1234 is at point 39 (my cue to build and ship the part), then
about 3 hours later I will get a broadcast from point 105 that serial
number 1234 has been built (my cue that my parts have been consumed).
In the intervening 3 hours, there will have been a bunch of broadcasts
through each point. Each broadcast is writted to a single table with
the following fields:
ProcessDate - The date/time stamp that the broadcast was received
SerialNumber - The serial number referenced by the broadcast
ReportingPoint - The point that generated the broadcast (either 39 or
105)
OK, so here is the query I want to build:
Whenever the query is run, it should find the serial number of most
current broadcast from 105. Then it should use that serial number to
find out the date/time that unit passed through 39. Then it should
return a list of everything that has passed through 39 between that
time and the current time.
If you need more info, or if this isn't clear, please ask. I don't
even know where to get started on this one.
Thanks!
TimThe way to approach these is to write it a little bit at a time,
building it up.

>Whenever the query is run, it should find the serial number of most
>current broadcast from 105.
SELECT TOP 1 ProcessDate, SerialNumber
FROM Whatever
WHERE ReportingPoint = 105
ORDER BY ProcessDate

>Then it should use that serial number to
>find out the date/time that unit passed through 39.
SELECT ProcessDate
FROM Whatever as W
JOIN (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate) as X
ON W.SerialNumber = X.SerialNumber
WHERE W.ReportingPoint = 39

>Then it should
>return a list of everything that has passed through 39 between that
>time and the current time.
SELECT *
FROM Whatever as A
WHERE ReportingPoint = 39
AND ProcessDate >=
(select ProcessDate
from Whatever as W
join (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate) as X
on W.SerialNumber = X.SerialNumber)
All untested, of course.
Roy Harvey
Beacon Falls, CT
On 25 Jul 2006 08:21:33 -0700, Timothy.Rybak@.gmail.com wrote:

>Let me preface this by saying that am relatively new to SQL.
>I have a database that is updated every10 to 15 seconds with broadcasts
>from our customer. These broadcasts come from 2 distinct points in
>their operation. The first point - 39 - tells me what to build and
>ship to them. The second point - 105 - tells me when they have used my
>product on the line. Every thing is controlled by a serial number.
>So, for example, at 8 AM they will send a broadcast saying that serial
>number 1234 is at point 39 (my cue to build and ship the part), then
>about 3 hours later I will get a broadcast from point 105 that serial
>number 1234 has been built (my cue that my parts have been consumed).
>In the intervening 3 hours, there will have been a bunch of broadcasts
>through each point. Each broadcast is writted to a single table with
>the following fields:
>ProcessDate - The date/time stamp that the broadcast was received
>SerialNumber - The serial number referenced by the broadcast
>ReportingPoint - The point that generated the broadcast (either 39 or
>105)
>OK, so here is the query I want to build:
>Whenever the query is run, it should find the serial number of most
>current broadcast from 105. Then it should use that serial number to
>find out the date/time that unit passed through 39. Then it should
>return a list of everything that has passed through 39 between that
>time and the current time.
>If you need more info, or if this isn't clear, please ask. I don't
>even know where to get started on this one.
>Thanks!
>Tim|||Please excuse my ignorance.
When I run the first part of the query, the TOP 1 is returning the
earliest instance of the 105 broadcast point in the table, instead of
the most recent entry. Is this correct, or am I doing something wrong
already?
The ProcessDate column is in the standard 'mm/dd/yyyy hh:mm:ss AM/PM'
format.
Roy Harvey wrote:[vbcol=seagreen]
> The way to approach these is to write it a little bit at a time,
> building it up.
>
> SELECT TOP 1 ProcessDate, SerialNumber
> FROM Whatever
> WHERE ReportingPoint = 105
> ORDER BY ProcessDate
>
> SELECT ProcessDate
> FROM Whatever as W
> JOIN (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate) as X
> ON W.SerialNumber = X.SerialNumber
> WHERE W.ReportingPoint = 39
>
>
> SELECT *
> FROM Whatever as A
> WHERE ReportingPoint = 39
> AND ProcessDate >=
> (select ProcessDate
> from Whatever as W
> join (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate) as X
> on W.SerialNumber = X.SerialNumber)
> All untested, of course.
> Roy Harvey
> Beacon Falls, CT
> On 25 Jul 2006 08:21:33 -0700, Timothy.Rybak@.gmail.com wrote:
>|||On 25 Jul 2006 09:45:42 -0700, Timothy.Rybak@.gmail.com wrote:

>Please excuse my ignorance.
>When I run the first part of the query, the TOP 1 is returning the
>earliest instance of the 105 broadcast point in the table, instead of
>the most recent entry. Is this correct, or am I doing something wrong
>already?
Simple explanation: I left off the DESC on the ORDER BY.
SELECT TOP 1 ProcessDate, SerialNumber
FROM Whatever
WHERE ReportingPoint = 105
ORDER BY ProcessDate DESC

>Then it should use that serial number to
>find out the date/time that unit passed through 39.
SELECT ProcessDate
FROM Whatever as W
JOIN (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate DESC) as X
ON W.SerialNumber = X.SerialNumber
WHERE W.ReportingPoint = 39

>Then it should
>return a list of everything that has passed through 39 between that
>time and the current time.
SELECT *
FROM Whatever as A
WHERE ReportingPoint = 39
AND ProcessDate >=
(select ProcessDate
from Whatever as W
join (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate DESC) as X
on W.SerialNumber = X.SerialNumber)
Roy|||This has been a great help! I have gotten the first two parts to work.
The last part is still giving me problems. Here is how SQL is
interpreting the code:
SELECT *
FROM [Whatever]
WHERE (ReportingPoint = '39') AND (ProcessDate >=
(SELECT W.ProcessDate, W.SerialNumber
FROM [Whatever] W INNER JOIN
(SELECT TOP 1 ProcessDate, SerialNumber
FROM [Whatever]
WHERE (ReportingPoint = 'D05')
ORDER BY ProcessDate DESC) X ON W.SerialNumber =
X.SerialNumber))
It is giving me the following error:
"Only one expression can be specified in the select list when the
subquery is not introducted with EXISTS"
While I understand the theory of what you wrote, I don't have the
knowledge to fix the issue.
Can you help?
Tim
Roy Harvey wrote:
> On 25 Jul 2006 09:45:42 -0700, Timothy.Rybak@.gmail.com wrote:
>
> Simple explanation: I left off the DESC on the ORDER BY.
> SELECT TOP 1 ProcessDate, SerialNumber
> FROM Whatever
> WHERE ReportingPoint = 105
> ORDER BY ProcessDate DESC
>
> SELECT ProcessDate
> FROM Whatever as W
> JOIN (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate DESC) as X
> ON W.SerialNumber = X.SerialNumber
> WHERE W.ReportingPoint = 39
>
>
> SELECT *
> FROM Whatever as A
> WHERE ReportingPoint = 39
> AND ProcessDate >=
> (select ProcessDate
> from Whatever as W
> join (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate DESC) as X
> on W.SerialNumber = X.SerialNumber)
> Roy|||On 25 Jul 2006 10:43:27 -0700, Timothy.Rybak@.gmail.com wrote:

>This has been a great help! I have gotten the first two parts to work.
> The last part is still giving me problems.
Sorry, I just have been asleep. Lots of problems, which I think I
have fixed.
create table Whatever
(ProcessDate datetime, -- The date/time stamp that the broadcast was
received
SerialNumber int, -- The serial number referenced by the broadcast
ReportingPoint int) -- The point that generated the broadcast (either
39 or 105)
INSERT Whatever values('1 Jan 2002 00:00', 123, 39)
INSERT Whatever values('1 Jan 2002 01:00', 456, 39)
INSERT Whatever values('1 Jan 2002 02:00', 789, 39)
INSERT Whatever values('1 Jan 2002 03:00', 368, 39)
INSERT Whatever values('1 Jan 2002 04:00', 246, 39)
INSERT Whatever values('1 Jan 2002 05:00', 468, 39)
INSERT Whatever values('1 Jan 2002 04:30', 123, 105)
INSERT Whatever values('1 Jan 2002 06:00', 456, 105)
-->Whenever the query is run, it should find the serial number of most
-->current broadcast from 105.
SELECT TOP 1 ProcessDate, SerialNumber
FROM Whatever
WHERE ReportingPoint = 105
ORDER BY ProcessDate DESC
ProcessDate SerialNumber
--- --
2002-01-01 06:00:00.000 456
-->Then it should use that serial number to
-->find out the date/time that unit passed through 39.
SELECT max(W.ProcessDate)
FROM Whatever as W
JOIN (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate DESC) as X
ON W.SerialNumber = X.SerialNumber
AND W.ProcessDate < X.ProcessDate
WHERE W.ReportingPoint = 39
---
2002-01-01 01:00:00.000
-->Then it should
-->return a list of everything that has passed through 39 between that
-->time and the current time.
SELECT *
FROM Whatever as A
WHERE ReportingPoint = 39
AND ProcessDate >=
(select W.ProcessDate
from Whatever as W
join (select TOP 1 ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
order by ProcessDate DESC) as X
on W.SerialNumber = X.SerialNumber
and W.ProcessDate < X.ProcessDate
where W.ReportingPoint = 39)
ProcessDate SerialNumber
ReportingPoint
--- --
--
2002-01-01 01:00:00.000 456 39
2002-01-01 02:00:00.000 789 39
2002-01-01 03:00:00.000 368 39
2002-01-01 04:00:00.000 246 39
2002-01-01 05:00:00.000 468 39
Roy|||Ok, I figured out, I think, that I can't have two values in the second
Select statement, or else the compison won't work - ProcessDate>= must
return a date, and a date only.
So, I fixed that. Now, I have the following:
SELECT *
FROM [Whatever] A
WHERE (ReportingPoint = '39') AND (ProcessDate >=
(SELECT W.ProcessDate
FROM [Whatever] W INNER JOIN
(SELECT TOP 1 ProcessDate,
SerialNumber
FROM [Whatever]
WHERE ReportingPoint = '105'
ORDER BY ProcessDate DESC) X ON
W.SerialNumber = X.SerialNumber))
I am getting this error now:
Subquery returned more than one value. This is not permitted when the
subquery follows =, !=, <, <=, >, >= or when the subquery is used as an
expression.
Any help?
Thanks!
Tim|||We must have posted at the same time.
Your new query is PERFECT!
Thank you so much for your patience, time, and effort!
Tim|||Ok, I got this to work, and everyone was happy.
Now, they want to be able to do this, but they want to be able to pick
the moment in time, rather than just using the most up to date data.
So, I tried to modify the code as follows, but I get the error: Must
Declare the variable @.GetDate
I don't want to declare it, I want the user to have to enter it. Any
ideas?
SELECT *
FROM Whatever as A
WHERE ReportingPoint = 39
AND ProcessDate >=
(select W.ProcessDate
from Whatever as W
join (select ProcessDate, SerialNumber
from Whatever
where ReportingPoint = 105
and ProcessDate >= @.GetDate
order by ProcessDate DESC) as X
on W.SerialNumber = X.SerialNumber
and W.ProcessDate < X.ProcessDate
where W.ReportingPoint = 39)
INSERT Whatever values('1 Jan 2002 04:00', 246, 39)
> INSERT Whatever values('1 Jan 2002 05:00', 468, 39)
> INSERT Whatever values('1 Jan 2002 04:30', 123, 105)
> INSERT Whatever values('1 Jan 2002 06:00', 456, 105)
>
> -->Whenever the query is run, it should find the serial number of most
> -->current broadcast from 105.
> SELECT TOP 1 ProcessDate, SerialNumber
> FROM Whatever
> WHERE ReportingPoint = 105
> ORDER BY ProcessDate DESC
> ProcessDate SerialNumber
> --- --
> 2002-01-01 06:00:00.000 456
> -->Then it should use that serial number to
> -->find out the date/time that unit passed through 39.
> SELECT max(W.ProcessDate)
> FROM Whatever as W
> JOIN (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate DESC) as X
> ON W.SerialNumber = X.SerialNumber
> AND W.ProcessDate < X.ProcessDate
> WHERE W.ReportingPoint = 39
> ---
> 2002-01-01 01:00:00.000
> -->Then it should
> -->return a list of everything that has passed through 39 between that
> -->time and the current time.
>
> SELECT *
> FROM Whatever as A
> WHERE ReportingPoint = 39
> AND ProcessDate >=
> (select W.ProcessDate
> from Whatever as W
> join (select TOP 1 ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> order by ProcessDate DESC) as X
> on W.SerialNumber = X.SerialNumber
> and W.ProcessDate < X.ProcessDate
> where W.ReportingPoint = 39)
> ProcessDate SerialNumber
> ReportingPoint
> --- --
> --
> 2002-01-01 01:00:00.000 456 39
> 2002-01-01 02:00:00.000 789 39
> 2002-01-01 03:00:00.000 368 39
> 2002-01-01 04:00:00.000 246 39
> 2002-01-01 05:00:00.000 468 39
> Roy|||What are the users using to run the query? A front-end application?
Query Analyzer? SQL Server has NO provision for prompting for input.
Perhaps the answer is to put it all in a stored procedure and pass
@.DateLimit as a parameter. Then, whatever the front end is, EXEC the
proc with the date (in single quotes) as a parameter.
Roy Harvey
Beacon Falls, CT
On 3 Aug 2006 12:24:59 -0700, Timothy.Rybak@.gmail.com wrote:
[vbcol=seagreen]
>Ok, I got this to work, and everyone was happy.
>Now, they want to be able to do this, but they want to be able to pick
>the moment in time, rather than just using the most up to date data.
>So, I tried to modify the code as follows, but I get the error: Must
>Declare the variable @.GetDate
>I don't want to declare it, I want the user to have to enter it. Any
>ideas?
>SELECT *
> FROM Whatever as A
> WHERE ReportingPoint = 39
> AND ProcessDate >=
> (select W.ProcessDate
> from Whatever as W
> join (select ProcessDate, SerialNumber
> from Whatever
> where ReportingPoint = 105
> and ProcessDate >= @.GetDate
> order by ProcessDate DESC) as X
> on W.SerialNumber = X.SerialNumber
> and W.ProcessDate < X.ProcessDate
> where W.ReportingPoint = 39)
>
>
>INSERT Whatever values('1 Jan 2002 04:00', 246, 39)

Sunday, February 19, 2012

Help with installing VS Tools

Hi,

I have a problem with the installation of SSCE31VSTools-ENU.exe into VS2005. The installation ended after a few seconds although in the event log there is information that the product is successfuly installed. However, when I run Visual studio there is no project under Smart Device regarding SQL Compact database or something similar (there are only templates for: device application, class library, control library, console application, empty project and nothing more)

VS2005 is in this version 8.0.50727.762 (SP.050727-7600)

In application event log there is: Product: Microsoft SQL Server 2005 Compact Edition Tools for Visual Studio 2005 [ENU] -- Configuration completed successfully.'"

Has anyone some idea if there is a problem or how to create SQL Compact database?

Thank you

Jarda

Have you tried installing the released bits?|||

Hi William,

I have the same problem that the gentlemen in the initial message described. I tried installing the released bits as you recommended, but the problem continued. Do you have any other suggestions?

Thanks for your help.

Mario

|||

Hi,

yes, it's yesterday release (Date Published: 1/11/2007).

Thanks

Jarda

|||

Did you install in the correct order?

The VSTools must be installed before the SQL Server ce Runtime.

Robert Wishlaw

|||

Hi,

my installastion order was:

Compact SDK

Compact Tools

Compact SQL edition

I hope that SDK didn't install runtime.

Thanks

Jarda

|||

Hi,

I made another try with installation. Uninstall all items regarding SQL Compact edition and try to install VS Tools first. However I got this message

"The upgrade patch cannot be installed by the Windows Installer service because the program to be upgraded may be missing, or the upgrade patch may update a different version of the program. Verify that the program to be upgraded exists on your computer and that you have the correct upgrade patch." :-(

Other items can be installed well (SDK, runtime).

I have no previous (beta) installation of Compact edition on my machine.

Please help me

Thanks

Jarda

btw. the link to download the VS Tools from MS site is wrong.

|||

jardajirava wrote:


the link to download the VS Tools from MS site is wrong.

Which link?

Robert Wishlaw|||

jardajirava wrote:

Hi,

I made another try with installation. Uninstall all items regarding SQL Compact edition and try to install VS Tools first. However I got this message

"The upgrade patch cannot be installed by the Windows Installer service because the program to be upgraded may be missing, or the upgrade patch may update a different version of the program. Verify that the program to be upgraded exists on your computer and that you have the correct upgrade patch." :-(

Other items can be installed well (SDK, runtime).

I have no previous (beta) installation of Compact edition on my machine.

Please help me

Thanks

Jarda

btw. the link to download the VS Tools from MS site is wrong.

Are you installing

Microsoft SQL Server 2005 Compact Edition Server Tools

or

Microsoft SQL Server 2005 Compact Edition Tools for Visual Studio 2005 Service Pack 1

?

The first is only for installations with IIS and SQL Server 2005. (not Express)

Be sure that the versions of the VS tools and runtime are the same. Get the current version of the VSTools from the link in the Related Resources section of the runtime download page at

http://www.microsoft.com/downloads/details.aspx?FamilyID=85e0c3ce-3fa1-453a-8ce9-af6ca20946c3&DisplayLang=en#QuickInfoContainer

Robert Wishlaw|||

Hi,

it is Tools for Visual Studio 2005 Service Pack 1 (VSTools). All downloads I made yesterday (11.1.2007) I try to download it again now but same information is displayed.

I have installed this extensions/addons in my Visual studio 2005:

Microsoft Visual Studio 2005
Version 8.0.50727.762 (SP.050727-7600)
Microsoft .NET Framework
Version 2.0.50727

Installed Edition: Professional

Microsoft Visual Basic 2005 77626-009-0000007-41168
Microsoft Visual Basic 2005

Microsoft Visual C# 2005 77626-009-0000007-41168
Microsoft Visual C# 2005

Microsoft Visual C++ 2005 77626-009-0000007-41168
Microsoft Visual C++ 2005

Microsoft Visual Studio Tools for Office 77626-009-0000007-41168
Microsoft Visual Studio Tools for the Microsoft Office System

Microsoft Visual Web Developer 2005 77626-009-0000007-41168
Microsoft Visual Web Developer 2005

Microsoft Web Application Projects 2005 77626-009-0000007-41168
Microsoft Web Application Projects 2005
Version 8.0.50727.762

Visual Studio 2005 Tools for Office Second Edition 77626-009-0000007-41168
Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System

Extensions for Windows WF
Windows Workflow Foundation Tools for Visual Studio

Microsoft Visual Studio 2005 Professional Edition - ENU Service Pack 1 (KB926601)
This service pack is for Microsoft Visual Studio 2005 Professional Edition - ENU.
If you later install a more recent service pack, this service pack will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/926601

SQL Server Analysis Services
Microsoft SQL Server Analysis Services Designer
Version 9.00.2047.00

SQL Server Integration Services
Microsoft SQL Server Integration Services Designer
Version 9.00.1399.00

SQL Server Reporting Services
Microsoft SQL Server Reporting Services Designers
Version 9.00.1399.00

Windows Installer XML Version 3.0
Votive 2005
Windows Installer XML (WiX) Toolset, Version 3.0
Primary Contributor: Justin Rockwood
Additional Contributors: Bob Arnson
Copyright ? Microsoft Corporation. All rights reserved.

XmlMvp.XPathmania 1.0
XmlMvp.XPathmania

Maybe this helps

Thanks

Jarda

|||

I am experiencing the same problem. After downloading the most recent bits (1/11/07) from the MS website I receive the error, on attempting to install the VS Tools for Visual Studio 2005 SP1 (SSCE31VStools-Enu.msi) that:

"The upgrade patch cannot be installed by the Windows Installer service because the program to be upgraded may be missing, or the upgrade patch may update a different version of the program. Verify that the program to be upgraded exists on your computer and that you have the correct upgrade patch."

I have confirmed I have installed VS 2005 SP1.

So... why does it reference an upgrade patch? I am installing the RTW version fresh, as I never installed the Beta.

Anyway... pretty frustrating :(

Ryan

|||

Sorry to reply to myself here... I discovered yesterday that my WMI installation is all messed up. This is rather odd as I develop WMI queries all the time against my localhost (just read queries, so I don't mess with the repositories etc).

I know WMI was working on Thursday before I installed the 3.1 Release of January 11 (in which I also uninstalled RC1). At any rate, WMI's class registrations are really messed up in a way the support articles and WMIDiag can't fix. Error message from WMI is 0x80040154 - Class not registered.

So... it makes some sense that the installer would not be able to find the correct product installed if it uses WMI to do so.

I am not able to point to the uninstall of RC1 or the install of the release version as "the problem", but it's an odd coincidence.

|||

I also get the same "The upgrade patch cannot be installed ..." message on VS SP1 when trying to install the tools.

|||

these post were helpful - I'm not going to try to install upgrade

Thanks

|||

Hi,

I just wanted to share that I was finally able to install the VS tools. The problem was that I had to uninstall and reinstall Visual Studio 2005 completely, then installed Visual Studio 2005 SP1, and finally installed the newly released code (including VS tools--> "SSCE31VSTools-ENU.exe").

I hope it helps.

Regards,

Mario