473,396 Members | 1,871 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,396 software developers and data experts.

Help with SQL Update Query -- Not sure how to approach this situation

Hello,

I have a rather large table in MS SQL 2000 that I'm writing reports in
Crystal from, but I'm unsure how to get the various data files (from
different departments) into the table. Below is a small chunk of the
table:

DeptCode;Type;AveMonthVolume;WorkedFTE;TotHours;Be nefits

I'm getting data from multiple places, but as I import the data, I
want it to populate the table with DeptCode and Type being the primary
keys.

If someone sends me the following file:
DeptCode;Type;AveMonthVolume;WorkedFTE
1000;Budget;100;200
1010;Target;233;433

And I get the following file from another source:
DeptCode;Type;TotHours;Benefits
1000;Budget;433;400
1010;Target;33;43

I want a simple way to import all this into the table so it looks like
this:
DeptCode;Type;AveMonthVolume;WorkedFTE;TotHours;Be nefits
1000;Budget;100;200;433;400
1010;Target;233;433;33;43

The data will be coming in delimited text and in Excel format. I
assume I can import his into MS SQL Enterprise Manager directly, but I
can't find any simple way of running in update query to import my
data. Also, I'd hate to use MS Access as the middle-man if at all
possible... but if this is the only option, I'll do it.

Does anyone have other suggestions? Above is only a small example...
the table has about 25 columns with various data I'll be collecting
from 3-4 departments, so it's a hodge podge of data to combine into
one report.

Thanks for any suggestions or ideas in solving this. Thanks in
advance...

Alex.
Jul 20 '05 #1
2 5784
Alex (al**@totallynerd.com) writes:
DeptCode;Type;AveMonthVolume;WorkedFTE;TotHours;Be nefits

I'm getting data from multiple places, but as I import the data, I
want it to populate the table with DeptCode and Type being the primary
keys.

If someone sends me the following file:
DeptCode;Type;AveMonthVolume;WorkedFTE
1000;Budget;100;200
1010;Target;233;433

And I get the following file from another source:
DeptCode;Type;TotHours;Benefits
1000;Budget;433;400
1010;Target;33;43

I want a simple way to import all this into the table so it looks like
this:
DeptCode;Type;AveMonthVolume;WorkedFTE;TotHours;Be nefits
1000;Budget;100;200;433;400
1010;Target;233;433;33;43

The data will be coming in delimited text and in Excel format. I
assume I can import his into MS SQL Enterprise Manager directly, but I
can't find any simple way of running in update query to import my
data. Also, I'd hate to use MS Access as the middle-man if at all
possible... but if this is the only option, I'll do it.


First, I would recommend you to use BCP to load the data, so that
you can automate the load. You can't spend your days loading files
in EM.

I would define a staging table for each file that I may get. Then
for each table, there would be something like:

INSERT target_tbl (DeptCode, Type)
SELECT DeptCode, Type
FROM staging_tbl s
WHERE NOT EXISTS (SELECT *
FROM target_tbl t
WHERE t.DeptCode = s.DeptCode
AND t.Type = s.Type)

UPDATE target_tbl
SET some_col = s.some_col,
...
FROM targget_tbl t
JOIN staging_tbl s ON t.DeptCode = s.DeptCode
AND t.Type = s.Type

Here, I assume that all columns, save DeptCode and Type, in the target
table would be nullable, so that you can receive the files in any
order.

Obviously you need to package the whole thing, so when you receive
a file, the right commands are executed.

Note: above I mentioned BCP, but you would also write a program in VB
for the task. Or you could use DTS, which may have support for this
built-in. I don't use DTS myself, but the friendly people in
microsoft.public.sqlserver.dts may have useful ideas.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
Alex,

I think the following will do what you want:

Import the first file into a table that has two more
columns than the file has data for (those two being TotHours
and Benefits). Then import the second file into a temporary
staging table with columns DeptCode, Type, TotHours, Benefits,
then

update T set
TotHours = Staging.TotHours,
Benefits = Staging.Benefits
from Staging
where Staging.DeptCode = T.DeptCode
and Staging.Type = T.Type

Alternatively, you can use table structures in SQL Server that
correspond to the import files, and create a view that looks
like your "rather large table," constructed by joining together
the separate tables on the primary key columns.

-- Steve Kass
-- Drew University
-- Ref: ECC5E7E8-F3DB-47FB-953C-BD504A3B249B

Alex wrote:
Hello,

I have a rather large table in MS SQL 2000 that I'm writing reports in
Crystal from, but I'm unsure how to get the various data files (from
different departments) into the table. Below is a small chunk of the
table:

DeptCode;Type;AveMonthVolume;WorkedFTE;TotHours;B enefits

I'm getting data from multiple places, but as I import the data, I
want it to populate the table with DeptCode and Type being the primary
keys.

If someone sends me the following file:
DeptCode;Type;AveMonthVolume;WorkedFTE
1000;Budget;100;200
1010;Target;233;433

And I get the following file from another source:
DeptCode;Type;TotHours;Benefits
1000;Budget;433;400
1010;Target;33;43

I want a simple way to import all this into the table so it looks like
this:
DeptCode;Type;AveMonthVolume;WorkedFTE;TotHours;B enefits
1000;Budget;100;200;433;400
1010;Target;233;433;33;43

The data will be coming in delimited text and in Excel format. I
assume I can import his into MS SQL Enterprise Manager directly, but I
can't find any simple way of running in update query to import my
data. Also, I'd hate to use MS Access as the middle-man if at all
possible... but if this is the only option, I'll do it.

Does anyone have other suggestions? Above is only a small example...
the table has about 25 columns with various data I'll be collecting
from 3-4 departments, so it's a hodge podge of data to combine into
one report.

Thanks for any suggestions or ideas in solving this. Thanks in
advance...

Alex.


Jul 20 '05 #3

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

Similar topics

10
by: R Camarda | last post by:
I have the following statement that takes quite a long time. Longest of any of my SQL statment updates. UPDATE F_REGISTRATION_STD_SESSION SET PREVIOUS_YEAR_SESSION_ID = ( SELECT...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
6
by: John Baker | last post by:
Hi: As those who have looked at this newsgroup recently will realize, I am a neophyte with Access, although I have experienced with Approach (the Lotus product). There are things I could easily...
4
by: Laura | last post by:
Here's the situation: I'm trying to use an update query to copy data from one row to another. Here is the situation: I have 5 companies that are linked to each other. I need to show all 5...
3
by: Larry Rekow | last post by:
I've built various web apps using Frontpage and/or ASP and Access, but now I'm trying to figure a way to do the following, perhaps in ASP.Net My friend gets parts lists in invoices (they are in...
2
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.