473,799 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;A veMonthVolume;W orkedFTE;TotHou rs;Benefits

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;A veMonthVolume;W orkedFTE
1000;Budget;100 ;200
1010;Target;233 ;433

And I get the following file from another source:
DeptCode;Type;T otHours;Benefit s
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;A veMonthVolume;W orkedFTE;TotHou rs;Benefits
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 5799
Alex (al**@totallyne rd.com) writes:
DeptCode;Type;A veMonthVolume;W orkedFTE;TotHou rs;Benefits

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;A veMonthVolume;W orkedFTE
1000;Budget;100 ;200
1010;Target;233 ;433

And I get the following file from another source:
DeptCode;Type;T otHours;Benefit s
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;A veMonthVolume;W orkedFTE;TotHou rs;Benefits
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.publi c.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.TotHour s,
Benefits = Staging.Benefit s
from Staging
where Staging.DeptCod e = 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;TotHo urs;Benefits

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;10 0;200
1010;Target;23 3;433

And I get the following file from another source:
DeptCode;Type; TotHours;Benefi ts
1000;Budget;43 3;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;TotHo urs;Benefits
1000;Budget;10 0;200;433;400
1010;Target;23 3;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
2212
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 s.previous_year_session_id FROM F_REGISTRATION_STD_SESSION R ,DS_V4_TARGET.dbo.D_H_Session_By_SessQtr S WHERE r.STUDENT_ID = F_REGISTRATION_STD_SESSION.STUDENT_ID
17
5030
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 cust_no, ded_type_cd, chk_no)
6
2149
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 do in Approach that appear to require some subtle and complex manipulation in Access. Herein lies my present problem. I have a number of tables, including one called "tblPO", which contains purchase orders. Some of the details of these change...
4
2284
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 companies on a form. 3 of the companies have common employees. I have a table that looks like this:
3
1074
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 an excel spreadsheet) that he has to classify as a certain type: eg. part number 111-111-111 is type R9, and part 222-222-222 is type 486, etc. we have a database that is not quite complete, but contains most of these classifications.
2
2914
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 avoid the problem by avoiding the table control or resorting to databound controls that better manage state for me. I hope to understand how to solve the problem by using the Table web control and sticking to the approach of building the table at run...
7
2197
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 another. I have tried declaring them as shared, public, friend, etc and I always get an error stating that something is not valid on a local variable declaration. For example, in the following code for Sub DataGrid_Select, I have CurrentID and...
16
2820
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 efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
0
5577
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
9686
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9540
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10475
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10250
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9068
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.