Is this doable?

Hi @emre… just playing around and wonder it its doable… I am getting an error

    DROP VIEW STOCK
    GO
    
    CREATE VIEW STOCK AS
    SELECT [InventoryItemName]
         
    FROM [PeriodicConsumptionItems]
    
    LEFT OUTER JOIN [InventoryItems] ON [InventoryItemId] = [InventoryItems].[Id]
    
    WHERE [PeriodicConsumptionId] = (SELECT TOP 1 [Id] FROM [PeriodicConsumptions] ORDER BY [Id] DESC)
          AND
    	  CONVERT(numeric(6,2),ISNULL([PhysicalInventory],([InStock]+[Added]-[Removed]-[Consumption]))) >= 0.05
    GO
    
    SELECT * FROM Stock ORDER BY [InventoryItemName]
GO

So… I took out everything before the CREATE VIEW

but…

Thanks!!!

G.

You should CREATE the View first by executing it in a Query editor, using the code you provided.

CREATE VIEW STOCK AS
    SELECT [InventoryItemName]

    FROM [PeriodicConsumptionItems]

    LEFT OUTER JOIN [InventoryItems] ON [InventoryItemId] = [InventoryItems].[Id]

    WHERE [PeriodicConsumptionId] = (SELECT TOP 1 [Id] FROM [PeriodicConsumptions] ORDER BY [Id] DESC)
          AND
    	  CONVERT(numeric(6,2),ISNULL([PhysicalInventory],([InStock]+[Added]-[Removed]-[Consumption]))) >= 0.05
    GO

Once the View is created, it is there forever, unless you delete it from the Database.

Then you should SELECT the View on it’s own within SambaPOS (the last part of your code, without the GO).

SELECT * FROM Stock ORDER BY [InventoryItemName]

The view is already created… thats why I am using the DROP command.
The views, are STATIC, that means tat if you want to see actual data you have to create them again… If you leave a view live the data gets old in the moment any cell of any table that once populated it gets updated…

G.

Really? I always thought views are not static :slight_smile:

OK… my mystaque… I was thinking in snapshots…

so, basically MR @QMcKay was right, and I discarted him. SORRY!!!

so, I will create a view save it, and then do a select over that view…

THANKS!!!

G.

2 Likes

lol you’ve discarded a sql god. pray for mercy before he wipes your sql backups.

uuuuuuuuuuuuuuuuuuuuuuuuuu
now I am in trouble…
I am gonna recite two hail marys…

LOL!!!

G.

PD I am rusty, very rusty… it has been a long time without doing any typing…

1 Like