Click here to Skip to main content
15,885,921 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 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

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900