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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting values into a table if they do not exist 2

Status
Not open for further replies.

Timcwilcox

Programmer
Jun 28, 2002
12
GB
I am very new to MSSQL7 and i am stuck with a program that appears to be very easy, but which i can not get to work.

I have the following SQL script (I appologise for the TABLE/COLUMN names, but this is someone elses database)

insert into XLABELS
SELECT CONVERT(numeric, (MP640100.MP64004 / CONVERT(numeric, SC010100.SC01014))) AS [NOBAGS],
MP640100.MP64001 AS [WORDER],
MP640100.MP64002 AS [STCODE],
MP640100.MP64004 AS [ORDQTY],
SC010100.SC01014 AS [UD5],
SC010100.SC01132 AS [EAN],
SUBSTRING(SC010100.SC01001, 4, 1) AS [COLOUR]
FROM SC010100 INNER JOIN MP640100 ON SC010100.SC01001 = MP640100.MP64002

This is working OK if the WORDER does not exist in XLABELS table, as this is has a UNIQUE index this is quite correct.

How do i get the script to only insert records into the XLABELS table if it does not exist?

Many Thanks

Tim
 
add something like

where worder not in(select worder from xlabels)

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top