Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Insert into a table excluding duplicates of a selected column

$
0
0

I have mytable:

 

IDNO

Item

Date

Level

1

X24

12/23/13 10:41

22996

2

X24

12/23/13 10:41

22996

3

X24

12/23/13 9:21

23256

4

X24

12/23/13 9:21

23256

5

X24

12/23/13 9:22

23256

6

X24

12/23/13 9:22

23256

7

X24

12/23/13 9:22

22916

that is a result of INSERT i.e.,

INSERT INTO myTABLE(Item,[Date],[Level])

values('X24','12/23/13 :22','22916')

I want the INSERT to exclude the duplicate level defined as the previous level in a selected column [Level]. This would avoid having to 'view' the table using:

SELECTi.IDNO,i.[Date],i.[Level]

FROMmytablei

INNERJOINmytabled

ONd.IDNO=i.IDNO-1

WHEREi.[Level]<>d.[Level]

IDNO is an identity column.

 

How can this INSERT be achieved without the overheads? 


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>