Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics RMS (Archived)

SQL Query to Change Quantities

(0) ShareShare
ReportReport
Posted on by 908

Hello, All from snow-ridden Upstate New York, where Spring is just a fairy tale...

So, I have yet another SQL need that I don't trust myself not to screw up, so I am turning to you experts out there.  We have a webstore through Nitrosell, (who have been great to work with.) I've a few vendors who drop ship, and so I am adding their products to the website. If an item is not in inventory, it's not available for sale on the website- so I've added another store in Headquarters to add additional inventory (999 pieces) to the vendors that will drop ship.  The problem is, the store in HQ is a fake, and is just there for this purpose. I don't have a store server connected to it. So, I need to be able to update quantities in that store via an SQL query in HQ Admin...   Ideally, I would like to be able to do this based on the first three characters of the item lookup code.

I've got:

UPDATE [item] SET [Quantity]=999 WHERE left([description], 3) = 'AAA';

but I'm faltering on how to do this in the specific store in question. (Store ID  is 12 Store Code is WEB.)  Any help is appreciated! Thanks!

*This post is locked for comments

  • Taier P Profile Picture
    Taier P 908 on at
    RE: SQL Query to Change Quantities

    Thanks, Fernando- I ran the query your provided in a test environment, tweaked the filter for the item lookup code a tiny bit, and it works well for my purposes.

    Archelle- thanks, but the the items I need to change already exist in headquarters, so they do not need to be created again for purposes of what I am doing.

    I appreciate everyone's help! :)

  • archelle16 Profile Picture
    archelle16 1,735 on at
    RE: SQL Query to Change Quantities

    oh no. Do not change item quantities in HQ Manager. Since you only create fake store for this purpose  and you dont have any store server connected on it, you can query directly in itemdynamic table since this table holds the current store item quantity as snapshotquantity. I guess, if you look item quantity for a specific store (your fake store) , you will not find anything because you dont have store server connected to it and no items uploaded in itemdynamic table. You need to add the items first in itemdynamic table specifying the new quantity.

    The above query works fine but i will add some extra on it.

    You can use this stored procedure:


    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Description: This will create item and update quantity in itemdynamic table.
    -- =============================================
    ALTER PROCEDURE RebuildItemDynamic
    @storecode AS NVARCHAR(30)
    AS
    BEGIN
    SET NOCOUNT ON
    DECLARE @rowcount AS INT
    DECLARE @storeid AS INT
    SELECT @storeid = ID FROM store WHERE StoreCode = @storecode
    IF (@storeid > 0)
    BEGIN
    PRINT 'Store ''' + @storecode + ''' exists!'
    SELECT * FROM Item WHERE ItemLookupCode LIKE 'AAA%'
    SET @rowcount = (SELECT @@ROWCOUNT)
    IF (@rowcount > 0)
    BEGIN
    PRINT 'There are ' + CAST(@rowcount AS VARCHAR) + ' item(s) found.'
    IF OBJECT_ID(N'tempdb..#TempToUpload') IS NOT NULL BEGIN DROP TABLE #TempToUpload END
    SELECT Item.ID As ItemID,
    @storeid as StoreID,
    Item.LastReceived, Item.LastSold,
    Item.Quantity AS SnapShotQuantity,
    Item.QuantityCommitted As SnapShotQuantityCommitted,
    GETDATE() AS SnapShotTime,
    Item.Price AS SnapShotPrice,
    Item.PriceA AS SnapShotPriceA,
    Item.PriceB AS SnapShotPriceB,
    Item.PriceC AS SnapShotPriceC,
    Item.SalePrice AS SnapShotSalePrice,
    Item.SaleStartDate AS SnapShotSaleStartDate,
    Item.SaleEndDate AS SnapShotSaleEndDate,
    Item.Cost AS SnapShotCost,
    Item.LastCost AS SnapShotLastCost,
    Item.ReplacementCost AS SnapShotReplacementCost,
    Item.PriceLowerBound AS SnapShotPriceLowerBound,
    Item.PriceUpperBound AS SnapShotPriceUpperBound,
    Item.ReorderPoint AS SnapShotReorderPoint,
    Item.RestockLevel AS SnapShotRestockLevel,
    Item.TaxID AS SnapShotTaxID
    INTO #TempToUpload
    FROM Item WHERE ItemLookupCode LIKE 'AAA%'

    UPDATE ItemDynamic SET
    dbo.ItemDynamic.Quantity = #TempToUpload.SnapShotQuantityCommitted,
    dbo.ItemDynamic.SnapShotQuantity = 100,
    dbo.ItemDynamic.SnapShotQuantityCommitted = #TempToUpload.SnapShotQuantityCommitted,
    ItemDynamic.SnapShotTime = GETDATE(),
    ItemDynamic.SnapShotPrice = #TempToUpload.SnapShotPrice,
    ItemDynamic.SnapShotPriceA = #TempToUpload.SnapShotPriceA,
    ItemDynamic.SnapShotPriceB = #TempToUpload.SnapShotPriceB,
    ItemDynamic.SnapShotPriceC = #TempToUpload.SnapShotPriceC,
    ItemDynamic.SnapShotSalePrice = #TempToUpload.SnapShotSalePrice,
    ItemDynamic.SnapShotSaleStartDate = #TempToUpload.SnapShotSaleStartDate,
    ItemDynamic.SnapShotSaleEndDate = #TempToUpload.SnapShotSaleEndDate,
    ItemDynamic.SnapShotCost = #TempToUpload.SnapShotCost,
    ItemDynamic.SnapShotLastCost = #TempToUpload.SnapShotLastCost,
    ItemDynamic.SnapShotReplacementCost = #TempToUpload.SnapShotReplacementCost,
    ItemDynamic.SnapShotPriceLowerBound = #TempToUpload.SnapShotPriceLowerBound,
    ItemDynamic.SnapShotPriceUpperBound = #TempToUpload.SnapShotPriceUpperBound,
    ItemDynamic.SnapShotReorderPoint = #TempToUpload.SnapShotReorderPoint,
    ItemDynamic.SnapShotRestockLevel = #TempToUpload.SnapShotRestockLevel,
    ItemDynamic.SnapShotTaxID = #TempToUpload.SnapShotTaxID
    FROM ItemDynamic INNER JOIN #TempToUpload ON #TempToUpload.ItemID = dbo.ItemDynamic.ItemID
    AND #TempToUpload.StoreID = dbo.ItemDynamic.StoreID
    seT @rowcount = (SELECT @@ROWCOUNT)
    PRINT 'Updated ' + CAST(@rowcount as VARCHAR) + ' record(s) in itemdynamic table.'

    DELETE #TempToUpload
    FROM #TempToUpload,dbo.ItemDynamic
    WHERE #TempToUpload.ItemID = dbo.ItemDynamic.ItemID
    AND #TempToUpload.StoreID = dbo.ItemDynamic.StoreID

    INSERT INTO dbo.ItemDynamic
    ( ItemID ,
    StoreID ,
    TaxID ,
    Quantity ,
    QuantityCommitted ,
    ReorderPoint ,
    RestockLevel ,
    LastReceived ,
    LastSold ,
    SnapShotQuantity ,
    SnapShotQuantityCommitted ,
    DeltaQuantity ,
    DeltaQuantityCommitted ,
    SnapShotTime ,
    DBTimeStamp ,
    SnapShotPrice ,
    SnapShotPriceA ,
    SnapShotPriceB ,
    SnapShotPriceC ,
    SnapShotSalePrice ,
    SnapShotSaleStartDate ,
    SnapShotSaleEndDate ,
    SnapShotCost ,
    SnapShotLastCost ,
    SnapShotReplacementCost ,
    SnapShotPriceLowerBound ,
    SnapShotPriceUpperBound ,
    SnapShotReorderPoint ,
    SnapShotRestockLevel ,
    SnapShotTaxID
    )
    SELECT ItemID ,
    StoreID ,
    TaxID ,
    Quantity ,
    QuantityCommitted ,
    ReorderPoint ,
    RestockLevel ,
    LastReceived ,
    LastSold ,
    SnapShotQuantity ,
    SnapShotQuantityCommitted ,
    DeltaQuantity ,
    DeltaQuantityCommitted ,
    SnapShotTime ,
    DBTimeStamp ,
    SnapShotPrice ,
    SnapShotPriceA ,
    SnapShotPriceB ,
    SnapShotPriceC ,
    SnapShotSalePrice ,
    SnapShotSaleStartDate ,
    SnapShotSaleEndDate ,
    SnapShotCost ,
    SnapShotLastCost ,
    SnapShotReplacementCost ,
    SnapShotPriceLowerBound ,
    SnapShotPriceUpperBound ,
    SnapShotReorderPoint ,
    SnapShotRestockLevel ,
    SnapShotTaxID
    from #TempToUpload
    PRINT 'Inserted ' + CAST(@rowcount as VARCHAR) + ' record(s) in itemdynamic table.'
    END
    ELSE
    BEGIN
    PRINT 'There are no items found.'
    END
    END
    ELSE
    BEGIN
    PRINT 'Store ''' + @storecode + ''' does not exists!'
    END
    END
    GO

    -- Copy the procedure above and run on your hq server. Dont forget to specify storecode.

    Please verify if this answers your question.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SQL Query to Change Quantities

    Taier - the Store Quantity tab shows data from the ITEMDYNAMIC table.

    Updating quantities on the backend is not a best practice. I would recommend you run this through the MS RMS support team and/or the Nitrosell support team.

    sp_columns ITEMDYNAMIC will show you column names and data types in this table. I don't know if the QUANTITY column in the ITEM table is an aggregate of the qty column or the snapshot qty column in the ITEMDYNAMIC table. If I recall correctly, there is a snapshot qty and a qty column in this table, so I cannot say which column update would work for this purpose. An update would be along the lines of

    UPDATE ITEMDYNAMIC

    SET (correct quantity column) = 100

    FROM ITEMDYNAMIC JOIN ITEM ON ITEMDYNAMIC.ITEMID = ITEM.ID

    WHERE STOREID = XXX

    AND  ITEMLOOKUPCODE LIKE 'AAA%'

    Before doing any updates run the SELECT below to see which records would get the update

    SELECT ITEMLOOKUPCODE, ID.*

    FROM ITEMDYNAMIC ID JOIN ITEM I ON ID.ITEMID = I.ID

    WHERE STOREID = XXX -- put in your storeid here

    -- if you don't know your storeid, run select * from store to retrieve

    AND  ITEMLOOKUPCODE LIKE 'AAA%'

    Again - get feedback and validations from MS / Nitrosell - and run these at your own risk, only after backing up your DB, and also after hours when you can restore from a backup if needed.

    Hope this helps.

  • Taier P Profile Picture
    Taier P 908 on at
    RE: SQL Query to Change Quantities

    I'm not certain of the table name, so I thought a screen shot may explain a bit better.

    I'm hoping for an SQL script which will update this field in Headquarters for all products with an item lookup code starting with "AAA".

  • Taier P Profile Picture
    Taier P 908 on at
    RE: SQL Query to Change Quantities

    I want to change the inventory of items in a specific store, using the first three characters of the product lookup code, via headquarters.

    Example:  All products in store #12 beginning with "AAA" should be changed to an on-hand quantity of 100.

  • archelle16 Profile Picture
    archelle16 1,735 on at
    RE: SQL Query to Change Quantities

    You mean, you want to change inventory of specific stores?  or change item quantity in itemdynamic table?

  • Taier P Profile Picture
    Taier P 908 on at
    RE: SQL Query to Change Quantities

    Can anyone help with the SQL Query that will allow me to change the inventory of items in a specific store ID through Headquarters using the first three characters of the item lookup code? [i.e.; all product codes beginning with AAA in store #12 set to '999' on hand.]

  • Taier P Profile Picture
    Taier P 908 on at
    RE: SQL Query to Change Quantities

    A stock take batch is not a viable solution, since it does not fit the parameter of what we are trying to accomplish. To recap: We have a separate store ID setup in Headquarters, which is solely there as a placeholder. The store is just a shell, and the only access is through Headquarters. The purpose behind this is to add a large quantity of merchandise to inventory without impacting an actual store. This would cause our website to see that there is a quantity of those products available for sale; these items are being drop shipped  from the vendor, so we want to open up a significant quantity above and beyond what we may have in a store. Since the first three letters of the product code indicate the vendor for us, I would like to be able to update quantities in the 'web' store for all items from a specific vendor to "999", to allow customers to order up to 999 that product online,which will in turn be drop shipped from the vendor.  Updating item quantities one at a time via is not an option. I need to be able to update all products based on the first three digits of the product code en mass. (I also need to be able to bring all of these products back down to 0 during certain holiday periods where some vendors do not drop ship.)

    Fernando: Nitrosell is very adaptable, and how orders are processed, and what inventory the site uses differs depending on your individual settings. If you're in a HQ environment, Nitrosell uses the HQ database to determine available inventory (we have it set to subtract 2 from this number as a safety buffer.) You can control which stores it includes in 'available inventory'.  Our company offices are adjacent to our biggest store, and our warehouse, so we currently have Nitrosell using inventory from Store #1, Our Warehouse, and this fake "webstore", since we can pull from all three without having to leave the building.  Web orders come to us here in the office; but you can have the orders go to the individual stores where the inventory is available if that's your preference- we just don't do it that way.   When we get an order for a product which is from a drop-ship vendor, we'd ship out the product of we have it on hand; if not, we simply relay the order to the dropshipper.

    TL;DR:  I need an SQL Query that will allow me to change the inventory of items in a specific store ID through Headquarters using the first three characters of the item lookup code. [i.e.; all product codes beginning with AAA in store #12 set to '999' on hand.]

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SQL Query to Change Quantities

    Never make a direct update to quantities using SQL, u should have a log for any quantity change, so the best way to do it is through a stock take batch

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SQL Query to Change Quantities

    How do you process the sales that are drop shipped? My understanding is the integration with Nitrosell, requires you "download" web orders into a POS lane. Where does Nitrosell route these orders?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,431 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,503 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans