Skip to content

Commit e141945

Browse files
authored
Merge pull request #150 from JocaPC/angularjs
Angularjs
2 parents cc9cdb0 + 346d5aa commit e141945

96 files changed

Lines changed: 8452 additions & 11375 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

samples/demos/BelgradeProductCatalogDemo/ProductCatalog.xproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,5 @@
1515
<PropertyGroup>
1616
<SchemaVersion>2.0</SchemaVersion>
1717
</PropertyGroup>
18-
<ItemGroup>
19-
<DnxInvisibleContent Include="wwwroot\index.html" />
20-
</ItemGroup>
2118
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" />
2219
</Project>

samples/demos/BelgradeProductCatalogDemo/sql-scripts/cleanup.sql renamed to samples/demos/BelgradeProductCatalogDemo/sql-scripts/0 cleanup.sql

File renamed without changes.

samples/demos/BelgradeProductCatalogDemo/sql-scripts/setup.sql renamed to samples/demos/BelgradeProductCatalogDemo/sql-scripts/1 setup.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ EXEC sp_addrolemember N'WebUserRole', N'WebUser'
1515
GO
1616

1717
DROP TABLE IF EXISTS Product
18-
DROP SEQUENCE IF EXISTS ProductIdSeq
18+
DROP SEQUENCE IF EXISTS ProductId
1919
GO
2020

21-
CREATE SEQUENCE ProductIdSeq AS int START WITH 29
21+
CREATE SEQUENCE ProductId AS int START WITH 29
2222

2323
CREATE TABLE Product (
24-
ProductID int DEFAULT (NEXT VALUE FOR ProductIdSeq) PRIMARY KEY,
24+
ProductID int DEFAULT (NEXT VALUE FOR ProductId) PRIMARY KEY,
2525
Name nvarchar(50) NOT NULL,
2626
Color nvarchar(15) NULL,
2727
Size nvarchar(5) NULL,
@@ -46,11 +46,11 @@ FROM OPENJSON (@products) WITH(
4646
GO
4747

4848
DROP TABLE IF EXISTS Company
49-
DROP SEQUENCE IF EXISTS CompanyIdSeq
49+
DROP SEQUENCE IF EXISTS CompanyId
5050
GO
51-
CREATE SEQUENCE CompanyIdSeq AS int START WITH 4
51+
CREATE SEQUENCE CompanyId AS int START WITH 4
5252
CREATE TABLE Company (
53-
CompanyID int PRIMARY KEY DEFAULT (NEXT VALUE FOR CompanyIdSeq),
53+
CompanyID int PRIMARY KEY DEFAULT (NEXT VALUE FOR CompanyId),
5454
Name nvarchar(50) NOT NULL,
5555
Address nvarchar(100) NULL,
5656
Email nvarchar(50) NULL,

samples/demos/BelgradeProductCatalogDemo/sql-scripts/json.sql renamed to samples/demos/BelgradeProductCatalogDemo/sql-scripts/2 json.sql

File renamed without changes.

samples/demos/BelgradeProductCatalogDemo/sql-scripts/setup-temporal.sql renamed to samples/demos/BelgradeProductCatalogDemo/sql-scripts/3 setup-temporal.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ CREATE TABLE History.Product(
2121

2222

2323
DECLARE @products NVARCHAR(MAX) =
24-
N'[{"ProductID":15,"Name":"Adjustable Race","Price":75.9900,"Quantity":50,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2015-05-07T03:39:52","ValidTo":"2015-08-07T03:40:01"},{"ProductID":16,"Name":"Bearing Ball","Price":35.9900,"Quantity":80,"CompanyID":2,"Data":{"ManufacturingCost":11.672700,"Type":"Part","MadeIn":"China"},"Tags":["promo"],"DateModified":"2015-05-07T03:39:52","ValidTo":"2015-08-07T03:40:01"},{"ProductID":17,"Name":"BB Ball Bearing","Price":75.0000,"Quantity":20,"CompanyID":3,"Data":{"ManufacturingCost":21.162700,"Type":"Part","MadeIn":"China"},"DateModified":"2015-05-07T03:39:52","ValidTo":"2015-08-07T03:40:01"},{"ProductID":18,"Name":"Blade","Color":"Silver","Price":20.9900,"Quantity":70,"CompanyID":4,"Data":{},"Tags":["new"],"DateModified":"2015-05-07T03:40:01","ValidTo":"2015-08-07T03:40:01"},{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":89.9900,"Quantity":80,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2015-08-07T03:40:01","ValidTo":"2015-11-07T03:40:09"},{"ProductID":16,"Name":"Bearing Ball","Color":"Blue","Size":"62","Price":15.9900,"Quantity":120,"CompanyID":2,"Data":{"ManufacturingCost":11.672700,"Type":"Part","MadeIn":"China"},"Tags":["promo"],"DateModified":"2015-08-07T03:40:01","ValidTo":"2015-11-07T03:40:09"},{"ProductID":17,"Name":"BB Ball Bearing","Color":"Magenta","Size":"62","Price":25.1900,"Quantity":65,"CompanyID":3,"Data":{"ManufacturingCost":21.162700,"Type":"Part","MadeIn":"China"},"DateModified":"2015-08-07T03:40:01","ValidTo":"2015-11-07T03:40:09"},{"ProductID":18,"Name":"Blade","Color":"Silver","Size":"62","Price":20.9900,"Quantity":80,"CompanyID":4,"Data":{},"Tags":["new"],"DateModified":"2015-08-07T03:40:01","ValidTo":"2015-11-07T03:40:09"},{"ProductID":18,"Name":"Blade","Color":"Silver","Size":"62","Price":20.1500,"Quantity":95,"CompanyID":4,"Data":{},"Tags":["new"],"DateModified":"2015-11-07T03:40:09","ValidTo":"2016-02-07T03:40:15"},{"ProductID":17,"Name":"BB Ball Bearing","Color":"Magenta","Size":"62","Price":37.9900,"Quantity":90,"CompanyID":3,"Data":{"ManufacturingCost":21.162700,"Type":"Part","MadeIn":"China"},"DateModified":"2015-11-07T03:40:09","ValidTo":"2016-02-07T03:40:15"},{"ProductID":16,"Name":"Bearing Ball","Color":"Blue","Size":"62","Price":45.9900,"Quantity":110,"CompanyID":2,"Data":{"ManufacturingCost":11.672700,"Type":"Part","MadeIn":"China"},"Tags":["promo"],"DateModified":"2015-11-07T03:40:09","ValidTo":"2016-02-07T03:40:15"},{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":105.9900,"Quantity":100,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2015-11-07T03:40:09","ValidTo":"2016-02-07T03:40:15"},{"ProductID":26,"Name":"Road-250 Black, 48","Color":"Black","Size":"48","Price":1250.9900,"Quantity":90,"CompanyID":2,"Data":{"ManufacturingCost":218.284600,"Type":"Bike","MadeIn":"UK"},"Tags":["new","promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":25,"Name":"Mountain-100 Silver, 38","Color":"Silver","Size":"38","Price":799.9900,"Quantity":90,"CompanyID":1,"Data":{"ManufacturingCost":262.792700,"Type":"Bike","MadeIn":"UK"},"Tags":["promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":24,"Name":"Road-650 Black, 52","Color":"Black","Size":"52","Price":529.9900,"Quantity":90,"CompanyID":5,"Data":{"Type":"Bike","MadeIn":"UK"},"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":23,"Name":"Long-Sleeve Logo Jersey, XL","Color":"Multi","Size":"XL","Price":49.9900,"Quantity":90,"CompanyID":4,"Data":{"ManufacturingCost":32.842700,"Type":"Clothes"},"Tags":["sales","promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":22,"Name":"Mountain Bike Socks, L","Color":"White","Size":"L","Price":19.9900,"Quantity":90,"CompanyID":3,"Data":{"ManufacturingCost":88.322700,"Type":"Clothes"},"Tags":["sales","promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":21,"Name":"Mountain Bike Socks, M","Color":"White","Size":"M","Price":9.5000,"Quantity":90,"CompanyID":2,"Data":{"Type":"Clothes"},"Tags":["sales","promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":20,"Name":"Sport-100 Helmet, Black","Color":"Black","Price":45.9900,"Quantity":10,"CompanyID":1,"Data":{"ManufacturingCost":22.987700,"Type":"Еquipment","MadeIn":"China"},"Tags":["new","promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":19,"Name":"Sport-100 Helmet, Red","Color":"Red","Price":34.9900,"Quantity":10,"CompanyID":3,"Data":{"ManufacturingCost":30.652700,"Type":"Еquipment","MadeIn":"China"},"Tags":["promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":32.9900,"Quantity":75,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2016-02-10T21:19:20","ValidTo":"2016-02-11T21:15:48"},{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":100.0000,"Quantity":75,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2016-02-11T21:15:48","ValidTo":"2016-02-11T21:24:12"},{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":120.0000,"Quantity":75,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2016-02-11T21:24:12","ValidTo":"2016-02-11T21:27:32"}]';
24+
N'[{"ProductID":15,"Name":"Adjustable Race","Price":75.9900,"Quantity":50,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2015-05-07T03:39:52","ValidTo":"2015-08-07T03:40:01"},{"ProductID":16,"Name":"Bearing Ball","Price":35.9900,"Quantity":80,"CompanyID":2,"Data":{"ManufacturingCost":11.672700,"Type":"Part","MadeIn":"China"},"Tags":["promo"],"DateModified":"2015-05-07T03:39:52","ValidTo":"2015-08-07T03:40:01"},{"ProductID":17,"Name":"BB Ball Bearing","Price":75.0000,"Quantity":20,"CompanyID":3,"Data":{"ManufacturingCost":21.162700,"Type":"Part","MadeIn":"China"},"DateModified":"2015-05-07T03:39:52","ValidTo":"2015-08-07T03:40:01"},{"ProductID":18,"Name":"Blade","Color":"Silver","Price":20.9900,"Quantity":70,"CompanyID":4,"Data":{},"Tags":["new"],"DateModified":"2015-05-07T03:40:01","ValidTo":"2015-08-07T03:40:01"},{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":89.9900,"Quantity":80,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2015-08-07T03:40:01","ValidTo":"2015-11-07T03:40:09"},{"ProductID":16,"Name":"Bearing Ball","Color":"Blue","Size":"62","Price":15.9900,"Quantity":120,"CompanyID":2,"Data":{"ManufacturingCost":11.672700,"Type":"Part","MadeIn":"China"},"Tags":["promo"],"DateModified":"2015-08-07T03:40:01","ValidTo":"2015-11-07T03:40:09"},{"ProductID":17,"Name":"BB Ball Bearing","Color":"Magenta","Size":"62","Price":25.1900,"Quantity":65,"CompanyID":3,"Data":{"ManufacturingCost":21.162700,"Type":"Part","MadeIn":"China"},"DateModified":"2015-08-07T03:40:01","ValidTo":"2015-11-07T03:40:09"},{"ProductID":18,"Name":"Blade","Color":"Silver","Size":"62","Price":20.9900,"Quantity":80,"CompanyID":4,"Data":{},"Tags":["new"],"DateModified":"2015-08-07T03:40:01","ValidTo":"2015-11-07T03:40:09"},{"ProductID":18,"Name":"Blade","Color":"Silver","Size":"62","Price":20.1500,"Quantity":95,"CompanyID":4,"Data":{},"Tags":["new"],"DateModified":"2015-11-07T03:40:09","ValidTo":"2016-02-07T03:40:15"},{"ProductID":17,"Name":"BB Ball Bearing","Color":"Magenta","Size":"62","Price":37.9900,"Quantity":90,"CompanyID":3,"Data":{"ManufacturingCost":21.162700,"Type":"Part","MadeIn":"China"},"DateModified":"2015-11-07T03:40:09","ValidTo":"2016-02-07T03:40:15"},{"ProductID":16,"Name":"Bearing Ball","Color":"Blue","Size":"62","Price":0,"Quantity":110,"CompanyID":2,"Data":{"ManufacturingCost":11.672700,"Type":"Part","MadeIn":"China"},"Tags":["promo"],"DateModified":"2015-11-07T03:40:09","ValidTo":"2016-02-07T03:40:15"},{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":105.9900,"Quantity":100,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2015-11-07T03:40:09","ValidTo":"2016-02-07T03:40:15"},{"ProductID":26,"Name":"Road-250 Black, 48","Color":"Black","Size":"48","Price":1250.9900,"Quantity":90,"CompanyID":2,"Data":{"ManufacturingCost":218.284600,"Type":"Bike","MadeIn":"UK"},"Tags":["new","promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":25,"Name":"Mountain-100 Silver, 38","Color":"Silver","Size":"38","Price":799.9900,"Quantity":90,"CompanyID":1,"Data":{"ManufacturingCost":262.792700,"Type":"Bike","MadeIn":"UK"},"Tags":["promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":24,"Name":"Road-650 Black, 52","Color":"Black","Size":"52","Price":529.9900,"Quantity":90,"CompanyID":5,"Data":{"Type":"Bike","MadeIn":"UK"},"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":23,"Name":"Long-Sleeve Logo Jersey, XL","Color":"Multi","Size":"XL","Price":49.9900,"Quantity":90,"CompanyID":4,"Data":{"ManufacturingCost":32.842700,"Type":"Clothes"},"Tags":["sales","promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":22,"Name":"Mountain Bike Socks, L","Color":"White","Size":"L","Price":19.9900,"Quantity":90,"CompanyID":3,"Data":{"ManufacturingCost":88.322700,"Type":"Clothes"},"Tags":["sales","promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":21,"Name":"Mountain Bike Socks, M","Color":"White","Size":"M","Price":9.5000,"Quantity":90,"CompanyID":2,"Data":{"Type":"Clothes"},"Tags":["sales","promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":20,"Name":"Sport-100 Helmet, Black","Color":"Black","Price":45.9900,"Quantity":10,"CompanyID":1,"Data":{"ManufacturingCost":22.987700,"Type":"Еquipment","MadeIn":"China"},"Tags":["new","promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":19,"Name":"Sport-100 Helmet, Red","Color":"Red","Price":34.9900,"Quantity":10,"CompanyID":3,"Data":{"ManufacturingCost":30.652700,"Type":"Еquipment","MadeIn":"China"},"Tags":["promo"],"DateModified":"2015-12-28T03:40:15","ValidTo":"2016-02-07T03:40:15"},{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":32.9900,"Quantity":75,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2016-02-10T21:19:20","ValidTo":"2016-02-11T21:15:48"},{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":100.0000,"Quantity":75,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2016-02-11T21:15:48","ValidTo":"2016-02-11T21:24:12"},{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":120.0000,"Quantity":75,"CompanyID":1,"Data":{"Type":"Part","MadeIn":"China"},"DateModified":"2016-02-11T21:24:12","ValidTo":"2016-02-11T21:27:32"}]';
2525
INSERT INTO History.Product(ProductID, Name, Color, Size, Price, Quantity, CompanyID, Data, Tags, DateModified, ValidTo)
2626
SELECT ProductID, Name, Color, Size, Price, Quantity, CompanyID, Data, Tags, DateModified, ValidTo
2727
FROM OPENJSON (@products) WITH(

samples/demos/BelgradeProductCatalogDemo/sql-scripts/temporal.sql renamed to samples/demos/BelgradeProductCatalogDemo/sql-scripts/4 temporal.sql

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ USE ProductCatalog
33
GO
44

55
-- Find the time when the first product(s) were inserted.
6-
select min(ValidFrom) from History.Product;
6+
select min(DateModified) from History.Product;
77

88
--List of current products.
99
select ProductID, Name, Color, Size, Price, Quantity
@@ -18,45 +18,47 @@ select *
1818
from dbo.diff_Product(17, '2015-07-28 13:20:00');
1919

2020
--Return full history of changes for product with ID 17.
21-
select ProductID, Name, Color, Size, Price, Quantity, ValidFrom, ValidTo
21+
select ProductID, Name, Color, Size, Price, Quantity, DateModified, ValidTo
2222
from Product FOR SYSTEM_TIME ALL
2323
where productid = 17
24-
order by ValidFrom desc;
24+
order by DateModified desc;
2525

2626
--Update product with ID 17.
2727
update Product
2828
set Color = 'Silver'
2929
where productid = 17;
3030

3131
--Verify that color is changed to 'Silver'.
32-
select ProductID, Name, Color, Size, Price, Quantity, ValidFrom, ValidTo
32+
select ProductID, Name, Color, Size, Price, Quantity, DateModified, ValidTo
3333
from Product
3434
where productid = 17;
3535

3636
--Return history of the product. You should see one additional row in history.
37-
select ProductID, Name, Color, Size, Price, Quantity, ValidFrom, ValidTo
37+
select ProductID, Name, Color, Size, Price, Quantity, DateModified, ValidTo
3838
from Product FOR SYSTEM_TIME ALL
3939
where productid = 17
40-
order by ValidFrom desc;
40+
order by DateModified desc;
4141

4242
--Restore product. Overwrite the latest version with the verison that was valid last year.
4343
exec RestoreProduct 17, '2015-11-07 03:40:09';
4444

4545
--Return history of the product with id 17 and verify that it current version and '2015-11-07 03:40:09' version are identical.
46-
select ProductID, Name, Color, Size, Price, Quantity, ValidFrom, ValidTo
46+
select ProductID, Name, Color, Size, Price, Quantity, DateModified, ValidTo
4747
from Product FOR SYSTEM_TIME ALL
4848
where productid = 17
49-
order by ValidFrom desc;
49+
order by DateModified desc;
5050

5151
-- Identify "spikes" in product price changes.
5252
with history as (
5353

54-
select ProductID, Name, Price, ValidFrom,
55-
LAG (Price, 1, 1) over (partition by ProductID order by ValidFrom) as PrevPrice,
56-
LEAD (Price, 1, 1) over (partition by ProductID order by ValidFrom) as NextPrice
54+
select ProductID, Name, Price, DateModified,
55+
LAG (Price, 1) over (partition by ProductID order by DateModified) as PrevPrice,
56+
LEAD (Price, 1) over (partition by ProductID order by DateModified) as NextPrice
5757
from dbo.Product for system_time all
58+
5859
)
59-
select ValidFrom AS ModifiedOn, ProductID, Name, PrevPrice, Price, NextPrice
60+
select DateModified, ProductID, Name, PrevPrice, Price, NextPrice
6061
from history
6162
where PrevPrice = NextPrice
62-
AND ABS(PrevPrice - Price)/PrevPrice >=0.5
63+
AND ABS(NextPrice - Price)/NextPrice >=0.1
64+

samples/demos/BelgradeProductCatalogDemo/sql-scripts/data-masking.sql renamed to samples/demos/BelgradeProductCatalogDemo/sql-scripts/5 data-masking.sql

File renamed without changes.

samples/demos/BelgradeProductCatalogDemo/sql-scripts/rls.sql renamed to samples/demos/BelgradeProductCatalogDemo/sql-scripts/6 rls.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ GO
1717

1818
/*
1919
TRY IT:
20-
EXEC sp_set_session_context 'CompanyID', -1
20+
EXEC sp_set_session_context 'CompanyID', '-1'
2121
select SESSION_CONTEXT(N'CompanyID')
2222
SELECT * FROM dbo.pUserCanAccessCompanyData(1)
2323
*/
@@ -28,7 +28,7 @@ CREATE SECURITY POLICY dbo.ClientAccessPolicy
2828
GO
2929

3030
/*
31-
EXEC sp_set_session_context 'CompanyID', -1
31+
EXEC sp_set_session_context 'CompanyID', '-1'
3232
SELECT * FROM Product
3333
3434
EXEC sp_set_session_context 'CompanyID', 1
@@ -37,7 +37,7 @@ SELECT * FROM Product
3737
EXEC sp_set_session_context 'CompanyID', 2
3838
SELECT * FROM Product
3939
40-
EXEC sp_set_session_context 'CompanyID',
40+
EXEC sp_set_session_context 'CompanyID', 777
4141
SELECT * FROM Product
4242
*/
4343

@@ -47,7 +47,7 @@ ALTER SECURITY POLICY dbo.ClientAccessPolicy
4747
GO
4848

4949
/*
50-
Don't allow company to enter a product for different product.
50+
Don't allow company to enter a product for different company.
5151
*/
5252
ALTER SECURITY POLICY dbo.ClientAccessPolicy
5353
ADD BLOCK PREDICATE dbo.pUserCanAccessCompanyData(CompanyID) ON dbo.Product
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
USE ProductCatalogDemo
2+
GO
3+
4+
with
5+
history as (
6+
7+
select ProductID, Name, Price, DateModified,
8+
LAG (Price, 1, 1) over (partition by ProductID order by DateModified) as PrevPrice,
9+
LEAD (Price, 1, 1) over (partition by ProductID order by DateModified) as NextPrice
10+
from dbo.Product for system_time all
11+
),
12+
spikes as (
13+
14+
select DateModified, ProductID, Name, PrevPrice, Price, NextPrice
15+
from history
16+
where PrevPrice = NextPrice
17+
AND ABS(PrevPrice - Price)/PrevPrice >=0.5
18+
19+
),
20+
logs as (
21+
22+
SELECT Page, [User], Time, Origin
23+
FROM OPENROWSET(BULK N'c:\JSON\logANSI.txt',
24+
FORMATFILE = 'c:\\JSON\ldjfmt.txt',
25+
CODEPAGE = '65001') as log
26+
CROSS APPLY
27+
OPENJSON (log.log_entry)
28+
WITH ( Page varchar(30), [User] varchar(20),Time datetime2, Origin varchar(20))
29+
30+
)
31+
select Page, [User], Time, Origin, PrevPrice, Price, NextPrice
32+
from logs JOIN spikes
33+
on ABS(DATEDIFF(second, Time, spikes.DateModified)) < 3000
34+
order by Time
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
select * from Product where ProductID = 17
2+
--FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
3+
4+
select [key] as [Column], value
5+
from OPENJSON(
6+
(select * from Product where ProductID = 17
7+
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER))
8+
9+
10+
select [key] as [Column], value
11+
from OPENJSON(
12+
(select * from Product FOR SYSTEM_TIME AS OF '2015-07-28 13:20:00'
13+
where ProductID = 17
14+
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER))
15+
16+
17+
select v1.[key] as [Column], v1.value as v1, v2.value as v2
18+
from OPENJSON(
19+
(select * from Product where ProductID = 17 FOR JSON PATH, WITHOUT_ARRAY_WRAPPER)) v1
20+
join OPENJSON(
21+
(select * from Product for system_time as of '2015-07-28 13:20:00' where ProductID = 17 FOR JSON PATH, WITHOUT_ARRAY_WRAPPER)) v2
22+
on v1.[key] = v2.[key]
23+
where v1.value <> v2.value

0 commit comments

Comments
 (0)