none
I need Help Why is the Query not working RRS feed

  • Question

  • SELECT ProductID,Name,Color,Quantity

    From Production.Product

    INNERJOIN production.ProductInventory

    On Product.ProductID =ProductInventory.ProductID

    INNERJOINproduction.Location

    On ProductInventory.LocationID =ProductInventory....LocationID

    Insert into Production.ProductInventory

    values (Finished Good Storage)

     

    Where color ='red'


    Wednesday, November 20, 2019 2:53 AM

All replies

  • It don't working, because the syntax of your INSERT statement is wrong, see INSERT (Transact-SQL) for correct syntax.

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Wednesday, November 20, 2019 5:20 AM
  • Can you also please explain what exactly you want to do with the queries?

    If you want ti INSERT records from the SELECT query results, then write the query like this:

    Insert into Production.ProductInventory(ProductID,Name,Color,Quantity)
    --values (Finished Good Storage) -- not needed
    SELECT ProductID,Name,Color,Quantity
    From Production.Product
    INNER JOIN production.ProductInventory On Product.ProductID = ProductInventory.ProductID
    INNER JOIN production.Location On ProductInventory.LocationID = ProductInventory.LocationID
    Where color ='red'


    ~manoj | SQLwithManoj.com

    Wednesday, November 20, 2019 5:25 AM
  • Hi JAC926, 

    Please try following script.

    ------If you have create table 'Production.ProductInventory'
    Insert into Production.ProductInventory
    -----values (Finished Good Storage)
    SELECT ProductID,Name,Color,Quantity
    From Production.Product
    INNERJOIN production.ProductInventory
    On Product.ProductID =ProductInventory.ProductID
    INNERJOINproduction.Location
    On ProductInventory.LocationID =ProductInventory....LocationID
    Where color ='red'
    
    ------If you have not  create table 'Production.ProductInventory'
    
    SELECT ProductID,Name,Color,Quantity
    into Production.ProductInventory
    From Production.Product
    INNERJOIN production.ProductInventory
    On Product.ProductID =ProductInventory.ProductID
    INNERJOINproduction.Location
    On ProductInventory.LocationID =ProductInventory....LocationID
    Where color ='red'

    Best Regards,

    Rachel 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 21, 2019 6:38 AM