I'm trying to run a select max() on a primary key/unique/non-identity
column then + 1, all while running an insert into.. select statement.
For some reason, the select max isn't quite doing the trick as I get a
primary key constraint error (MSG 2627) in SQL server!
It's probably something simple like adding quotes or parenthesis or
something, but I've tried...
Here's my code:
INSERT INTO [frameinventory]
([frameid]
,[framenumber]
,[framename]
,[colornumber]
,[a]
,[dbl]
,[templelength]
,[b]
,[ed]
,[cost]
,[retailprice]
,[upccode]
,[eyesize]
,[bridgesize]
,[groupcost]
,[colordescriptio n]
,[lenscolor]
,[lenscolorcode]
,[circumference]
,[edangle]
,[frontprice]
,[halftemplespric e]
,[templesprice]
,[manufacturernam e]
,[brandname]
,[collectionname]
,[gendertype]
,[agegroup]
,[activestatus]
,[productgroupnam e]
,[rimtype]
,[material]
,[frameshape]
,[country]
,[yearintroduced]
,[upccode_type])
select (select max(frameid) + 1 from frameinventory) , fpc, stylename,
colorcode, a, dbl, temple, b, ed, completeprice,
((framesdata.co mpleteprice*160 0)+5), upc, eye, bridge, completeprice,
colordescriptio n, lenscolor, lenscolorcode, circumference, edangle,
frontprice, halftemplespric e, templesprice, manufacturernam e,
brandname, collectionname, gendertype, agegroup, 'Active',
productgroupnam e, rimtype, material, frameshape, country,
yearintroduced, 'UPC'
from framesdata
where not exists (select * from frameinventory where
frameinventory. upccode=framesd ata.upc)
THANKS!
							
						
					column then + 1, all while running an insert into.. select statement.
For some reason, the select max isn't quite doing the trick as I get a
primary key constraint error (MSG 2627) in SQL server!
It's probably something simple like adding quotes or parenthesis or
something, but I've tried...
Here's my code:
INSERT INTO [frameinventory]
([frameid]
,[framenumber]
,[framename]
,[colornumber]
,[a]
,[dbl]
,[templelength]
,[b]
,[ed]
,[cost]
,[retailprice]
,[upccode]
,[eyesize]
,[bridgesize]
,[groupcost]
,[colordescriptio n]
,[lenscolor]
,[lenscolorcode]
,[circumference]
,[edangle]
,[frontprice]
,[halftemplespric e]
,[templesprice]
,[manufacturernam e]
,[brandname]
,[collectionname]
,[gendertype]
,[agegroup]
,[activestatus]
,[productgroupnam e]
,[rimtype]
,[material]
,[frameshape]
,[country]
,[yearintroduced]
,[upccode_type])
select (select max(frameid) + 1 from frameinventory) , fpc, stylename,
colorcode, a, dbl, temple, b, ed, completeprice,
((framesdata.co mpleteprice*160 0)+5), upc, eye, bridge, completeprice,
colordescriptio n, lenscolor, lenscolorcode, circumference, edangle,
frontprice, halftemplespric e, templesprice, manufacturernam e,
brandname, collectionname, gendertype, agegroup, 'Active',
productgroupnam e, rimtype, material, frameshape, country,
yearintroduced, 'UPC'
from framesdata
where not exists (select * from frameinventory where
frameinventory. upccode=framesd ata.upc)
THANKS!
 
	
Comment