Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

table design
I am a novice with SQL, so please don't hold it against me.

I have a text file that I import into SQL.   (easy enough)
There are not many fields (maybe 20)
THere are is One field named PO which can be in multiple times.  Another
field name STYLE that can also have duplicate rcords.   BUT   The same PO
number with the same STYLE number will not duplicate.
But I will have another text file to import that would update info for the
record that has the same PO and Style.   How would I do that?
ANy place on teh Internet where I might be able to figure this out?



Report this thread to moderator Post Follow-up to this message
Old Post
Johnfli
10-29-05 01:23 AM


Re: table design
Its a one to many relationship for PO and STYLE.

-------
Regards ,
C#, VB.NET , SQL SERVER , UML , DESIGN Patterns Interview question book
http://www.geocities.com/dotnetinterviews/
My Interview Blog
http://spaces.msn.com/members/dotnetinterviews/


Report this thread to moderator Post Follow-up to this message
Old Post
shiv_koirala@yahoo.com
10-29-05 08:23 AM


Re: table design
On Fri, 28 Oct 2005 13:37:11 -0700, Johnfli wrote:

>I am a novice with SQL, so please don't hold it against me.
>
>I have a text file that I import into SQL.   (easy enough)
>There are not many fields (maybe 20)
>THere are is One field named PO which can be in multiple times.  Another
>field name STYLE that can also have duplicate rcords.   BUT   The same PO
>number with the same STYLE number will not duplicate.
>But I will have another text file to import that would update info for the
>record that has the same PO and Style.   How would I do that?
>ANy place on teh Internet where I might be able to figure this out?
>

Hi Johnfli,

Import your second text file to a staging table. Then merge it onto the
main table with the following two commands:

UPDATE MainTable
SET    Column1 = StagingTable.Column1,
Column2 = StagingTable.Column2,
-- repeat for all columns except PO and STYLE
FROM   MainTable
JOIN   StagingTable
ON     StagingTable.PO = MainTable.PO
AND    StagingTable.STYLE = MainTable.STYLE

INSERT INTO MainTable (PO, STYLE, Column1, Column2, ...)
SELECT PO, STYLE, Column1, Column2, ...
FROM   StagingTable
WHERE NOT EXISTS
(SELECT *
FROM   MainTable
WHERE  MainTable.PO = StagingTable.PO
AND    MainTable.STYLE = StagingTable.STYLE)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

Report this thread to moderator Post Follow-up to this message
Old Post
Hugo Kornelis
10-30-05 01:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

MS SQL Server archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 03:35 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006