473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Creating Tables and automatically inserting data-HELP!!

I have created a table with the following columns...
Date(datetime),Actual (Int),Planned (Int)

I need to insert weekending dates starting from 23/04/04 looping
thru'for the next 52weeks automatically into the date column.

Then in the actual and planned colums, I need to insert a count of
some records in the table.

I will appreciate help on a SQL query to achieve this!
Jul 20 '05 #1
5 2046
On 19 Apr 2004 11:14:00 -0700, Sparrow wrote:
I have created a table with the following columns...
Date(datetime),Actual (Int),Planned (Int)

I need to insert weekending dates starting from 23/04/04 looping
thru'for the next 52weeks automatically into the date column.

Hi Sparrow,

For inserting the dates:

DECLARE @LoopDate datetime
DECLARE @LoopCount int
SET @LoopDate = '20040423' -- yyyymmdd is allways recognised,
-- regardless of locale setting
SET @LoopCount = 0
WHILE @LoopCount <= 52
BEGIN
INSERT YourTable([Date])
VALUES (@LoopDate)
SET @LoopDate = DATEADD(day, 7, @LoopDate)
SET @LoopCount = @LoopCount + 1
END

(untested)

Then in the actual and planned colums, I need to insert a count of
some records in the table.

I will appreciate help on a SQL query to achieve this!


I can only help if you tell more precisely what you want - a count of
"some" records in the table (what table? the one you just inserted the
next 53 fridays in?) is not concise enough.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2


Thanks for ur help Hugo!..

The count for the actual will be derived from the a table where I can do
a count of the actual records where the date is <= the date I have put
in the table.
And for the planned where date = the date in the table at those
intervals within a year!

I hope this makes sense.

Regards,

Sparro

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
On 20 Apr 2004 08:27:05 GMT, Sparro Chi wrote:


Thanks for ur help Hugo!..

The count for the actual will be derived from the a table where I can do
a count of the actual records where the date is <= the date I have put
in the table.
Hi Sparro,

This part is easy:

UPDATE YourTable
SET Actual = (SELECT COUNT(*)
FROM YourTable AS A
WHERE A.[Date] <= YourTable.[Date])

(untested)

And for the planned where date = the date in the table at those
intervals within a year!

I hope this makes sense.


Actually, it doesn't. It would help if you could post:
* the actual DDL used to declare the table (and any other tables
relevant to the question),
* illustrative examples of data in other tables relevant to the
question,
* desired output.

The preferred way to describe table structure is DDL (create table
statements), including all relevant constraints and indexes.
The preferred way to describe sample data is in the form of insert
statements.
If DDL ans inserts are posted, I'll almost allways copy and paste it
into Query Analyzer and test the queries I suggest. Without DDL and
sample data, I can only provide untested suggestions.

The preferred way to describe desired output is in a tabular format.
Make sure it's aligned properly when viewed with an unproportional
font.
Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #4
Hugo,

This is the structure of the table:

CREATE TABLE ActualVPlanned (
AVP_ID int NULL ,
AVP_DATE datetime NULL ,
ACTUAL int NULL ,
PLANNED int NULL
)
GO

AVP_ID is an Auto increasing field,
Then,
AVP_date is a field populated with weekending dates for the next 52
weeks
ACTUAL is calculated using count (taskactual)where date <= the
corresponding row in the AVP_Date column
PLANNED is calculated using count (taskplanned)where date <= the
corresponding row in the AVP_Date column

I hope this gives a better view.

Thanks for ur help.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5
On 20 Apr 2004 13:27:13 GMT, Sparro Chi wrote:
Hugo,

This is the structure of the table:

CREATE TABLE ActualVPlanned (
AVP_ID int NULL ,
AVP_DATE datetime NULL ,
ACTUAL int NULL ,
PLANNED int NULL
)
GO

AVP_ID is an Auto increasing field,
Then,
AVP_date is a field populated with weekending dates for the next 52
weeks
ACTUAL is calculated using count (taskactual)where date <= the
corresponding row in the AVP_Date column
PLANNED is calculated using count (taskplanned)where date <= the
corresponding row in the AVP_Date column

I hope this gives a better view.


Hi Sparrow,

I still don't know what (taskactual) and (taskplanned) are, but for
now I'll assume they are columns in one or two other tables.

Step 1: Fill all required values for AVP_DATE in ActualVPlanned, using
the technique I outlined in my first reply to you.

Step 2: Calculate ACTUAL and PLANNED:

BEGIN TRANSACTION
UPDATE ActualVPlanned
SET ACTUAL = (SELECT COUNT(*)
FROM taskactual
WHERE taskactual.[date] <= ActualVPlanned.AVP_DATE),
PLANNED = (SELECT COUNT(*)
FROM taskplanned
WHERE taskplanned.[date] <= ActualVPlanned.AVP_DATE)

Step 3: Inspect results and rollback or commit as required.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sparrow | last post by:
I have created a table with the following columns... Date(datetime),Actual (Int),Planned (Int) I need to insert weekending dates starting from 23/04/04 looping thru'for the next 52weeks...
1
by: Ed Hawkes | last post by:
I am having the following problem and any help would be GREATLY appreciated: In an application I am developing, at some points we create a new table. When I create this table on another users...
8
by: Stephen Poley | last post by:
One disadvantage of using a simple text editor to produce HTML is that it is relatively time-consuming to put in the proper typographical quotation marks and dashes. A round tuit having arrived...
31
by: Neil | last post by:
I have an Access 2000 MDB with ODBC linked tables to a SQL Server 7 back end. I currently have a selections table in the front end file which the users use to make selections of records. The table...
2
by: Chris via AccessMonster.com | last post by:
I have done something like this a million years ago my developer skills have diminished to nothing but now I am at a new job trying to regroup what I lost. This one came across my desk recently. I...
3
by: m3ckon | last post by:
Hi there, I can succesfully create a word doc from my asp.net page, but I have 2 issues I need to resolve in order to use it in my app: 1) Creating a table: I seem unable to create a table,...
1
by: DWiggin | last post by:
We are getting deadlock errors (sporadically) on a batch job we've created. This job runs against a SQL Server 2000 back-end. The first step of the batch job is to run a DDL script to drop...
4
by: sethington | last post by:
Here is my situation. I have ODBC Rights to a SQL database but I have 4 users who need to get to this information but because they are contractors they are not allowed to get there own ODBC access. ...
3
by: lmeeson | last post by:
hi guys, I am totally new to coding so please bare with me. I have a file upload field in a form on a PHP page for users to upload pictures, i also have the following fields in my MySQL database ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
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...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.