Wednesday, March 28, 2012
Is it possible to merge date from 2 or 3 tables into a View?
each table has a DateTime column for the date and time the event occurs,
along with some data specific to the event. Can I pull all events from the
three tables into a single View so that the data appears as if it were one
single table, and use a where condition for the date range so that only
events in a certain date range for all three tables appear? So my output
might look like this
EventDate Type
=================
1/1/2001 1
1/2/2001 2
2/1/2003 3
... etc...
Not sure if this makes sense but. I really don't care about the data in the
tables for this example, only the ocurrances in dates ranges for all three.
thanks,
JIM
EventTables
CREATE TABLE dbo.Type1Events (
id int NOT NULL IDENTITY (1, 1),
eventDate datetime NOT NULL,
somedata text NOT NULL
) ON [PRIMARY]
TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE dbo.Type2Events (
id int NOT NULL IDENTITY (1, 1),
eventDate datetime NOT NULL,
somedata text NOT NULL
) ON [PRIMARY]
TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE dbo.Type3Events (
id int NOT NULL IDENTITY (1, 1),
eventDate datetime NOT NULL,
somedata text NOT NULL
) ON [PRIMARY]
TEXTIMAGE_ON [PRIMARY]
GO
INSERT INTO Type1Events ( eventDate, someData ) values ( '1/1/2001',
'data1' )
INSERT INTO Type1Events ( eventDate, someData ) values ( '1/1/2002',
'data2' )
INSERT INTO Type2Events ( eventDate, someData ) values ( '1/1/2003',
'data3' )
INSERT INTO Type2Events ( eventDate, someData ) values ( '2/1/2002',
'data4' )
INSERT INTO Type3Events ( eventDate, someData ) values ( '3/1/2001',
'data5' )
INSERT INTO Type3Events ( eventDate, someData ) values ( '4/1/2002',
'data6' )
INSERT INTO Type2Events ( eventDate, someData ) values ( '5/1/2006',
'data7' )
INSERT INTO Type1Events ( eventDate, someData ) values ( '6/1/2004',
'data8' )
INSERT INTO Type3Events ( eventDate, someData ) values ( '7/1/2005',
'data9' )
GOcreate view events
as
select eventDate, someData from Type1Events
union all
select eventDate, someData from Type2Events
union all
select eventDate, someData from Type3Events
go|||Sorry, a more complete solution is:
create view events
as
select 1 as eventType, eventDate, someData from Type1Events
union all
select 2, eventDate, someData from Type2Events
union all
select 3, eventDate, someData from Type3Events
go|||Jeff,
Thanks a lot!, I figured it should be easy but havn't used union much so...
thanks,
JIM
"JeffB" <jeff.bolton@.citigatehudson.com> wrote in message
news:1142016783.270339.21280@.u72g2000cwu.googlegroups.com...
> Sorry, a more complete solution is:
> create view events
> as
> select 1 as eventType, eventDate, someData from Type1Events
> union all
> select 2, eventDate, someData from Type2Events
> union all
> select 3, eventDate, someData from Type3Events
> go
>
Is it possible to merge continuously between 8am and 5pm?
changes occur, they need to replicate fairly quickly (within 30 minutes),
but changes may not occur in every hour.
I think it would be most efficient to run continuous rather than every 10
minutes. However, I would really like replication to not be running at all
outside of the 8am-5pm window. Is it possible to have continuous
replication, but only from 8am to 5pm? The SQL Enterprise Manager does not
seem to allow for it.
Rob Kraft
Sure. Add a job that runs at 8AM and again at 5PM. What does this job do?
It changes the schedule on the replication job.
Mike
Principal Mentor
Solid Quality Learning
"More than just Training"
SQL Server MVP
http://www.solidqualitylearning.com
http://www.mssqlserver.com
sql
is it possible to merge 2 columns into 1 in SQL server
Hi..
is it possible to merge 2 columns into 1 to hold data like this... When the user imports the file in particular file they will be
ACT_ID1 Tot_ACT1 ACT_ID2 TOT_ACT2 ..... until 15
BB 1245.45 CT some amount ....
The 2 letter character may change prob for each file.. at leat i know of somethem may change
So while i transfer the data to the production database can is it possible to do some thing like
COL1 BB 1245.45
COL2 CT 12456.12 etc..
Any help will be appreciated.
Regards
Karen
Hi Karen
You could try two inserts. Do the first one on column 1 and 2 and then do the second one on 3 and 4 in the same destination table. Put them in a stored proc that gets called on the import. You may also want to add a column that identifies which set of columns they are from.
|||Charles,
Thanks for your answer... I am getting these acronymns from another dbf file which the user imports... so does it makes sense to create a table called acronymns (may change the name later) and have the following fields..
AcryID(int identity) Name Description
so when i am importing the information into the production database i can reference the acronymn from this table by inner joining it and then insert the data into the production database... like the way you suggested...
Is this approach good or would it slow down things...
Any other suggestions are welcome too.
Regards
Karen
|||Anything you can do to normalize the data is a good thing, in terms of performance, maintenance and scalability.
|||so do u think the approach is good or bad ?
|||
Yes. Here's an article about normalization:
http://en.wikipedia.org/wiki/Database_normalization
Is it possible to mass update stats?
I'm fairly new to SQL Server and I'm just wondering if it's possible to Update Statistice for all indexes somehow? I'm looking at the Update Statistics command and it doesn't seem to be possible.
The situation we have is a reporting DB that basically has all it's tables truncated and remade every night by some DTS jobs that import from another datasource and change the data and build some denormalzed tables etc.
Some of the large Insert operations go from taking 8 mins to taking several hours sometimes and updating the stats seems to fix the problem for a while. So I'd like to make sure the optimizer has all the latest stats for all tables.
Any other advice would be appreciated.
Cheers.EXECUTE sp_updatestats 'resample' (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_ua-uz_14kz.asp)
-PatP|||Cool cheers ... From the help on that it doesn't seem like I can set the sample size.
From that I noticed links to sp_createstats so I might drop the stats and recreate them with a higher sample rate.
THANKS!
Is it possible to manually run a subscription?
subscription to run? The only thing I can see is to create an additional
schedule on the fly set for a few minutes in advance.
Any help would greatly be appriciated.
JoshYou can open Enterprise Manager and find the job with the same
scherduled time, right click and tell it to run.|||holy crap, no wonder sql server agent has to be running. I'm a bit
ashamed I never investigated this before.
I actually need to fire off the subscription through code. I'd imagine
this could be done then through SQLDMO.
Thanks for your response.
Lon wrote:
> You can open Enterprise Manager and find the job with the same
> scherduled time, right click and tell it to run.
>
Is it possible to make use of database relationships in a join?
SELECT Products.ProductName from Products, Categories
WHERE Categories.CategoryName = 'Seafood' AND
Products.CategoryID = Categories.CategoryID
In this query you use 'Products.CategoryID = Categories.CategoryID' to give the relation between the two tables. But if you already added the relationships to your database, this should be known.
My question is, why is it necessary to add the relation in the query when the relationships are already in the database? Is it somehow possible to ommit the relation in the query and make use of the relationships in the database.
Kind regards,
Iwan RotteveelRelationships (also known as Declarative Referential Integrity constraints) are not for DML operations, but rather for enforcement of data integrity that can be affected by DML should there be no DRI on related tables.|||thats a good note...
Just so im clear, DDL as in INSERT, UPDATE, etc
DML as in JOIN etc?|||No,
DDL = Data Definition Language (CREATE, ALTER)
DML = Data Manipulation Language (INSERT, UPDATE, SELECT, DELETE)
Regards,
hmscott
thats a good note...
Just so im clear, DDL as in INSERT, UPDATE, etc
DML as in JOIN etc?|||And lest we forget...
DCL
EDIT: Damn...some lexicon...|||Did you mean "at least" or "...and lest" ?
-PatP
Is it possible to make linked server from SQL Server 2000 to MySQL
I need transfer data from mysql to SQL Server 2000. Does anyone know how to
make a linked server from SQL Server 2000 (SP3 or SP4) to MySQL? If it's
possible, I need install mysql client software in my SQL Server box. Am I
right? What kind procedures I need follow?
Regards!
-ChenAm Mon, 5 Jun 2006 12:29:02 -0700 schrieb Chen:
> Hi All,
> I need transfer data from mysql to SQL Server 2000. Does anyone know how t
o
> make a linked server from SQL Server 2000 (SP3 or SP4) to MySQL? If it's
> possible, I need install mysql client software in my SQL Server box. Am I
> right? What kind procedures I need follow?
> Regards!
> -Chen
http://forums.devx.com/showthread.php?t=18963
bye, Helmut|||Install the mysql drivers on the SQL Server box. You can
download them from:
http://dev.mysql.com/downloads/
The follow the steps you can find in books online under
sp_addlinkedserver.
-Sue
On Mon, 5 Jun 2006 12:29:02 -0700, Chen
<Chen@.discussions.microsoft.com> wrote:
>Hi All,
>I need transfer data from mysql to SQL Server 2000. Does anyone know how to
>make a linked server from SQL Server 2000 (SP3 or SP4) to MySQL? If it's
>possible, I need install mysql client software in my SQL Server box. Am I
>right? What kind procedures I need follow?
>Regards!
>-Chensql