2015-04-22 82 views
-5

我查詢不工作是如下:我的查詢不按預期工作

CREATE TABLE #tempCal (
    CategoryId BIGINT 
    ,CategoryName NVARCHAR(max) 
    ,ElementWeight MONEY 
    ,MakingCharges MONEY 
    ,GemstoneAttribute NVARCHAR(max) 
    ,AlloyAttribute NVARCHAR(max) 
    ,Rates MONEY 
    ) 

--insert into #tempCal(CategoryId,CategoryName,ElementWeight,MakingCharges,GemstoneAttribute,AlloyAttribute,Rates) 
--values 
DECLARE @iterator BIGINT = (
     SELECT max(MstJewelleryProduct.ID) 
     FROM MstJewelleryProduct 
     ) 

INSERT INTO #tempCal (
    CategoryId 
    ,CategoryName 
    ,ElementWeight 
    ,MakingCharges 
    ,GemstoneAttribute 
    ,AlloyAttribute 
    ,Rates 
    ) 
VALUES (
    (
     SELECT MstJewelleryProduct.ElementWeight 
      ,MstJewelleryProduct.Element_Price 
      ,MstJewelleryProduct.MakingCharges 
      ,MstJewelleryProduct.GemstoneAttribute 
      ,MstJewelleryProduct.AlloyAttribute 
      ,MstJewelleryCategory.ID 
      ,MstJewelleryCategory.CategoryName 
      ,MstRates.Rates 
      ,MstJewelleryOffers.OfferAmount 
     FROM MstJewelleryProduct 
     INNER JOIN MstJewelleryCategory ON MstJewelleryProduct.CategoryID = MstJewelleryCategory.ID 
     LEFT JOIN MstRates ON MstJewelleryProduct.CategoryID = MstRates.CategoryId 
     LEFT JOIN MstJewelleryOffers ON MstJewelleryProduct.CategoryID = MstJewelleryOffers.ProductCategory 
      AND MstJewelleryOffers.IsActive = 1 
     WHERE MstJewelleryProduct.IsActive = 1 
     ) 
    ) 

SELECT * 
FROM #tempCal 

DROP TABLE #tempCal 
+3

你可以請說什麼不工作? – JFPicard

+0

你得到了什麼輸出?或錯誤? –

+0

如果沒有可回答的問題,您可能需要先嚐試將子查詢中返回的值與臨時表中定義的列對齊。 –

回答

0

的語法(插入進入)是不正確的。當您使用(選擇)時,您不需要使用()。請參閱此link以檢查正確的語法。