Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select into problem

Status
Not open for further replies.

DaveJohnson

Technical User
Feb 13, 2005
13
GB
Hi

Could anyone tell me where i am going wrong the first part works fine and updates existing records but the second half does not insert any new records.


UPDATE SY01200 SET

INET1 = (SELECT EMAIL FROM F100_VM_EMAIL WHERE SY01200.MASTER_ID = F100_VM_EMAIL.ACCOUNT),
INET8 = (SELECT NOTES FROM F100_VM_EMAIL WHERE SY01200.MASTER_ID = F100_VM_EMAIL.ACCOUNT)

FROM SY01200, F100_VM_EMAIL
WHERE SY01200.MASTER_ID IN (SELECT ACCOUNT FROM F100_VM_EMAIL) AND MASTER_TYPE = 'VEN'


INSERT INTO SY01200 (Master_Type, Master_ID, ADRSCODE, INETINFO, INET1, INET2, INET3, INET4, INET5, INET6, INET7, INET8)

SELECT 'VEN', F100_VM_Email.ACCOUNT, F100_VM_Email.ACCOUNT, ' ', F100_VM_Email.EMAIL, ' ', ' ', ' ', ' ', ' ', ' ', F100_VM_Email.NOTES

FROM SY01200, F100_VM_EMAIL
WHERE F100_VM_EMAIL.ACCOUNT NOT IN (SELECT MASTER_ID FROM SY01200)

Many Thanks
 
And the error is?

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
There is no error reported just affects 0 records when I know there are records in F100_VM_EMAIL and not in SY01200.

Thanks
 
Make a backup of your database before you run this (just in case).

Code:
INSERT 
INTO   SY01200(Master_Type, Master_ID, ADRSCODE, INETINFO, INET1, INET2, INET3, INET4, INET5, INET6, INET7, INET8)
SELECT 'VEN', F100_VM_Email.ACCOUNT, F100_VM_Email.ACCOUNT, ' ', F100_VM_Email.EMAIL, ' ', ' ', ' ', ' ', ' ', ' ', F100_VM_Email.NOTES
FROM   F100_VM_EMAIL
       Left Join SY01200
         On F100_VM_EMAIL.ACCOUNT = SY01200.MASTER_ID
Where  SY01200.MASTER_ID Is NULL

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
I just read carefully your query. I have some notes:

First you don't need SY01200 table at all (in your SELECT part of the query).
Second, if you need it you didn't put ANY join statement between sys01200 and F100_VM_Email in your query.


George query must works for you.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Backup and inserted your code and it worked fine.

Thank you

George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top