Showing posts with label newbie. Show all posts
Showing posts with label newbie. Show all posts

Wednesday, March 21, 2012

Read + Statistics from SQl

I have a very big problem. I must do this vbs or i'll be fired...Help me, i'm newbie at vb...

I have a SQL2000 database with a columns defined like that:
Server name, data, service1, service2, ..., service7.

Records looks something like that:

k2-ss-ss, 2003-08-13, 1, 0, 1, 1, 1, 1, 0.
k2-qq-ww, 2003-08-14 0, 0, 1, 1, 0, 0, 1.

"1" - means running
"0" - means stopped

example
a write: "service1", "2003-08-11 ", "2003-08-14"
Script list, that service1 worked 94,3% at choosed period, on k2-ss-ss.
Script list, that service1 worked 06,3% at choosed period, on k2-qq-ww.

Records to the database are writen every 3 minutes.

Can anyone help me? Some piece of code?:(create procedure SaveYerAss
(@.Service varchar(50),
@.StartDate datetime,
@.EndDate datetime)
as

select @.Service + ' worked ' +
case @.Service
when 'Service1' then 100 * Service1Count/RecordCount
when 'Service2' then 100 * Service2Count/RecordCount
when 'Service3' then 100 * Service3Count/RecordCount
when 'Service4' then 100 * Service4Count/RecordCount
when 'Service5' then 100 * Service5Count/RecordCount
when 'Service6' then 100 * Service6Count/RecordCount
when 'Service7' then 100 * Service7Count/RecordCount
end
+ '% at choosed period, on ' + Servername + '.'
From
(select servername,
sum([service1]) Service1Count,
sum([service2]) Service2Count,
sum([service3]) Service3Count,
sum([service4]) Service4Count,
sum([service5]) Service5Count,
sum([service6]) Service6Count,
sum([service7]) Service7Count,
count(*) RecordCount
from [YerDataTable]
where [data] between @.StartDate and @.EndDate) SummarizedData|||bm, your subquery lacks a
group by servername
clause.|||Well, he ought to do SOMETHING to save his own job! :D|||bm, I take it as a THANKS. :D|||What do you want to bet that was a homework problem?

Tuesday, March 20, 2012

RE: Please help me!!! SQL Newbie here - need help with inserting of records!!!!!

Hi,

I am a SQL and databases newbie and this might seem like a really simple question but I just can't seem to get my head around the concept. I'm building a C# music database app. that manages music files but I am having serious trouble wrapping my head around the initial inserts of all the music MP3s on a hard drive - how do I do the inserts?

I am using the following tables (I have simplified them):

ARTIST table

ARTISTID (PK)

ARTISTNAME

ALBUM table

ALBUMID (PK)

ARTISTID (FK)

ALBUMTITLE

TRACKALBUM

TRACKID(PK)

ALBUMID(FK)

TRACKNUMBER

TRACK

TRACKID

TRACKTITLE

So whats the best way to go about inserting new tracks into this database? I realise this is probably a very simple thing but any help would be VERY MUCH APPRECIATED as this is one of the core functions of my app.

Hi,

The concept of having Foreign key relationships is that you need to have the entry in the parent table to put a referecing key entry in the child table. I would suggest building the tables top-down

1. First populate the Artist table

2. Next populated the Album table and so on

With the referential integrity in place, this would ensure that you do not insert anything in the child table that is not there in the parent table. I am assuming that these tables have one-to-many FK relationships.

The following link could be helpful: http://msdn2.microsoft.com/en-us/library/bb332381.aspx

HTH