Click here to Skip to main content
12,349,725 members (28,085 online)
Rate this:
 
Please Sign up or sign in to vote.
OLTP named FYP Project
Data Warehouse named FYPStarSchema
Once i have load data warehouse now i want to load it again but it give an error of violation of primary key(duplication cannot be allowed)

Insert Into Product_Dimension(Product_key,Product_Name,Product_Colour,Sale_Price,Cost_Price)
SELECT P_ID, articleNO, colour, Cur_Sale_Price, CostPrice
FROM [FYP Project].dbo.Product
select max(Product_key) from Product_Dimension
int a=max(Product_key)
where Product_key>a
SELECT MAX(Product_key) AS largest FROM Product_Dimension WHERE Product_key > largest
select * from Product_Dimension
Posted 8-Dec-12 22:15pm
Edited 8-Dec-12 23:00pm
v2
Comments
fahad hassan 2050 9-Dec-12 4:56am
   
OLTP named FYP Project
Data Warehouse named FYPStarSchema
Once i have load data warehouse now i want to load it again but it give an error of violation of primary key(duplication cannot be allowed)

Insert Into Product_Dimension(Product_key,Product_Name,Product_Colour,Sale_Price,Cost_Price)
SELECT P_ID, articleNO, colour, Cur_Sale_Price, CostPrice
FROM [FYP Project].dbo.Product
select max(Product_key) from Product_Dimension
int a=max(Product_key)
where Product_key>a
SELECT MAX(Product_key) AS largest FROM Product_Dimension WHERE Product_key > largest
select * from Product_Dimension

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Your query makes no sense at all - even ignoring the sytax errors. What it effectivly comes down to is:
SELECT MAX(column) AS largest FROM table WHERE column > largest
Which is clearly silly - it can't return any records that are larger than the largest value, because if a record was larger than the largest, it would be the largest! Paradox, I'm afraid.

If you want to return the largest value in a column then just do that:
SELECT MAX(Product_Key) FROM Product_Dimension
That will return a single value, the largest in the table.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160621.1 | Last Updated 9 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100