|
The INSERT command can contain a SELECT
INSERT INTO Destination
SELECT Column1, Column2, Column3
FROM SourceTable
|
|
|
|
|
Depending on what you mean by "summarize it", I suspect you may be looking for a "GROUP BY" construct.
INSERT INTO tblWeekly
SELECT userName, SUM(stats)
FROM tblDaily
GROUP BY userName;
Can you give a few-record example of 'daily stats' and then what a summary of those stats should look like in the weekly table?
David
|
|
|
|
|
thanks for the reply.
i have a table "DailyUsage", which has 3 fields, namely Username, TheDate, DailyCount. primary key is a combination of Username and TheDate.
Now, because this table is pretty big, cos its storing daily usage for the last year, I want to do a sort of round robin methodoligy so my reports can run alot quicker.
So, ive created a table called "weeklyUsage" which will have Username, TheDate, and WeeklyCount. tbl WeeklyUsage will have only for example the last 3 or 4 weeks of data in it. So, I need to do a SUM of DailyCounts for each username for the last 3 or 4 weeks and then insert into tbl WeeklyUsage...
|
|
|
|
|
Sorry about taking so long to respond; I have been out of town.
How about
INSERT INTO weeklyUsage
SELECT Username, SUM(DailyCount)
FROM DailyUsage
GROUP BY Username
WHERE TheDate > DATE() - 21;
to get summaries for the last three weeks.
David
|
|
|
|
|
thanks for the reply.
i tried that DATE() function but its not working, im using SQL Server.dont know if thats the problem.
Is that 'DATE()' suppose to give me the current date?
|
|
|
|
|
Yes, the current date. In Oracle, it's "SYSDATE()" plus some other synonyms. I don't use SQL Server, and don't know what it wants.
Since you didn't give examples, I am not sure the query I provided will give what you want, but from your description, i *THINK* it's what you want. Let me know how it turns out.
David
|
|
|
|
|
yes, it works.
its GETDATE() for sql server.
Thanks Alot!
|
|
|
|
|
Good morning guys,
i'm using sql pervasive 9.0 for accpac. I have a password on one of my databases, so that i can't get in. I would like to remove it(i mean reset the old password) and set a new one.
Someboby please can help me find any solution about this?
Regards.
|
|
|
|
|
Did you check with the Customer Support?
Clickety[^]
|
|
|
|
|
not yet! thanks for your advice. try it today.
|
|
|
|
|
Hi all
I need to get some information on how cobol handles database? and how can we access the MS SQL Database from ACUCOBOL?
I would really appreciate if any body can forward links on this topic,
Bhagirathi
|
|
|
|
|
|
Hi colin
Thanks fr your time , i did go thru some sites, actually i don't know cobol at all and i am looking for code logic to access sql databse from cobol and how different it is from access any dbms
i am not able to spot any good code refernce i have checked out
cobug-cobol users group and some other sites, i need a basic idea that is all
Regards
Bhagirathi
|
|
|
|
|
Since SQL Server is a relational database I would imagine that the way you access it is fairly similar to any othe relational database system.
Of course, COBOL has such a long legacy that it has connected to all manner of weird and wonderful databases in its time.
|
|
|
|
|
What the advantages of having lots of subquery....?
|
|
|
|
|
Plenty of time to drink tea while you wait for the query to run.
|
|
|
|
|
Having lots of subquerys will slow down your query. The more a query does the longer it will take, which makes sence right?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
|
basically there is no advantages of having sub queries...
|
|
|
|
|
I have made an SQL Server 2005 instance (SERVER2005) be a linked server in an MSDE 2000 instance (MSDE2000). Everything is fine with the setup and I can run queries on tables in a database in Server 2005 instance from the MSDE 2000 instance as follows:
SELECT * FROM [SERVER2005].[ContactsDB].[dbo].[Contacts]
This is how I added the linked server to MSDE2000 instance:
USE master;
GO
EXEC sp_addlinkedserver 'SERVER2005', N'SQL Server'
GO
The problem is that if I execute a stored procedure as follows:
DECLARE @ContactID INT
DECLARE @ContactName NVARCHAR(36)
SET @ContactID = 1
EXEC [SERVER2005].[ContactsDB].[dbo].[dalsp_GetContactName] @ContactID, @ContactName OUTPUT
the execution of the stored procedure is not error-free and the following error message accompanies the results: 'A severe error occurred on the current command. The results, if any, should be discarded.'
If I link two SQL Server 2005 instances the execution is smooth. What can the problem be? Is it the provider? Why does executing a SELECT statement not bring and error yet executing a stored procedure bring an error?
|
|
|
|
|
Did some research myself and found the cause. Thought I should share it with you.
In the event that you add an SQL Server 2005 instance as a linked server to an MSDE 2000 instance, any stored procedure in SQL Server 2005 instance you choose to execute from the MSDE 2000 instance should not have a PRINT statement.
This applies to even stored procedures called by the stored procedure you are calling directly.
If you have statements like:
PRINT N’Hello’
, then error, "A severe error occurred on the current command. The results, if any, should be discarded" will be returned.
Have a nice day.
|
|
|
|
|
I have got three tables...Departments, Branch, and Employees
my table branch is having empid field only..but i have to get empname from employees table
I wanna write a stored procedure to get brid, branchname and empname..?
Branch table and Employees table have empid as common field...!!
Please anyone help me in writing a sql query to overcome this....
Thanks in advance
SAJAN A PILLAI
C#.NET Programmer
TELESOFT INDIA PVT LTD...
BANGALORE
"Winners don't do different things. They do things differently. ...
|
|
|
|
|
|
hi hope this works on
select b.id,b.branchname,e.empname
from branch b inner join employees e on b.empid=e.id
the above query gives to the branchid,branchname and empname where empid is matching with branch table empid.
get back for any queries.
|
|
|
|
|
I have a application based on an access database. I want to be able to distribute the data in the database on one unit and drop it into another unit installed on another machine. I figured i could export the database to xml and then import the file on the other machine? If this is what to do how do i do it? Any other ideas appreciated
mike
|
|
|
|