I have the following query: -
SELECT mOnCallAdd.OpName,mOnCallAdd.SchedName,mOnCallAdd.FirstListing, moncallAdd.Initials,
-
DATEADD(MINUTE, mOnCallAdd.AddTime, DATEADD(DAY, mOnCallAdd.AddDate, '12/31/1899')) as Added,
-
DATEADD(MINUTE, mOnCallAdd.StartOnCallTime, DATEADD(DAY, mOnCallAdd.StartOnCallDate, '12/31/1899')) as OnCallDate,
-
DATEADD(MINUTE, mOnCallAdd.duration, DATEADD(MINUTE, mOnCallAdd.StartOnCallTime, DATEADD(DAY, mOnCallAdd.StartOnCallDate, '12/31/1899'))) as OnCallEnd,
-
convert(smalldatetime,convert(float,T2.Timestamp)/1440-1) as Deleted
-
FROM mdr.dbo.mOnCallAdd
-
INNER JOIN (SELECT mOnCallDelete.Timestamp, mOnCallDelete.SchedName FROM mOncallDelete WHERE mOnCallDelete.TimeStamp >= datediff(mi, '1899-12-31 00:00:00.000', @datesince) AND mOnCallDelete.SchedName = @schedname) T2
-
ON mOnCallAdd.SchedName = T2.SchedName
-
WHERE mOnCallAdd.TimeStamp >= datediff(mi, '1899-12-31 00:00:00.000', @datesince) AND mOnCallAdd.SchedName = @schedname
-
ORDER BY OnCallDate
-
and what I'm trying to do is instead of showing the "added" field and "deleted" field is just to simply have a field called "activity" which will show anything that "activity" (either that something has been added or deleted, and the time and date when this was done) and it was suggested to me to use Union. Here is the DDL: -
-
CREATE TABLE [dbo].[mOnCallAdd] (
-
[ID] [int] IDENTITY (1, 1) NOT NULL ,
-
[RecID] [decimal](18, 0) NOT NULL ,
-
[Timestamp] [int] NULL ,
-
[SchedName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Rank] [int] NULL ,
-
[StartOnCallDate] [int] NULL ,
-
[StartOnCallTime] [int] NULL ,
-
[Override] [int] NULL ,
-
[FirstListing] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Duration] [decimal](18, 0) NULL ,
-
[TimeDifference] [decimal](18, 0) NULL ,
-
[AddDate] [int] NULL ,
-
[AddTime] [int] NULL ,
-
[Initials] [nvarchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Opname] [nvarchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Comment] [nvarchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field0] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field1] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field2] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field3] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field4] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field5] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field6] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field7] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field8] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field9] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field10] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[Field11] [nvarchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
-
[MainSchedName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
-
) ON [PRIMARY]
-
GO
-
Both the moncalladd and moncalldelete tables are the same as far as structure goes.
Here is a sample line of data: -
1 70550 55426893 Schedname 0 38490 1020 0 Dr Doctor 840 0 38490 1293 TG 8199
-
The output I want would be this: -
Op Name SchedName FirstListing Activity OncallStart OncallEnd
-
___________________________________________________________________________________________________________________________________________
-
8467 BUTTERCUP Data, Sample 2011-03-20 03:57:00 Added 2011-03-17 17:00:00 2011-03-1808:00:00
-
8467 BUTTERCUP Data, Sample 2011-03-20 03:57:00 Deleted 2011-03-17 17:00:00 2011-03-18 08:00:00
-
Can anyone please assist.
Thank you.
1 1079
Trigger is your best bet...
Good Luck!!!
~~ CK
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jonnychang |
last post by:
What is the purpose of using union in this class?
Class A {
public:
union {
int age;
char * name;
double amount;
}
};
|
by: Rich Protzel |
last post by:
Hello,
So my table contains say 100,000 records, and I need to group the
categories in fld1 by the highest count of subcategories. Say fld1
contains categories A, B, C, D, E.
All of these...
|
by: Lyn |
last post by:
Hi,
How do you bind the output columns from a UNION query when the fields from
the two tables have different names? Consider this query (WHERE clauses
omitted)...
SELECT SurnameBirth,...
|
by: Susan Bricker |
last post by:
For those of you who have been following my posts - they all pertain to
a Dog Competition Organization's Database.
There are three classes that the dogs can participate:
NOVICE, OPEN, and...
|
by: steve.kim |
last post by:
Hello,
I'm trying to make a class like below...
class myClass {
public:
// ctor / dtor
....
// methods
|
by: simbarashe |
last post by:
Hie
could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as...
|
by: bgreenspan |
last post by:
Hi Everyone, I'm back for some more expert help. Here's what I am
doing and what I tried.
My database has entries with Contract Names and Expiry Dates, among
other fields. I have a form...
|
by: asmian |
last post by:
I have a problem query that's not playing nice with my webhost's MySQL server. On the face of it it looks quite innocuous but I need a better way as they've forbidden me to run it any more!
Here's...
|
by: muddasirmunir |
last post by:
I had two tables, one new customers and the other new suppliers.
Now I want to show all the customer and suppliers in one combo box.
I am using a recordset by coding
recordset1.open...
|
by: flashvenom |
last post by:
Trying to wrap my head around how a good SQL search string would work. I have three tables (two in the example below for learning) with different column names (but similar data.) I'm using aliases to...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |