So I'm trying to get some data in tsql (MSSQL2014) where I use a subquery to get a sum of some foreign key'd data table.
The structure looks like this:
TABLE [AggregateData](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Aggregate_UUID] [uniqueidentifier] NOT NULL,
[DataDate] [date] NOT NULL,
[SizeAvailable] [bigint] NOT NULL,
[SizeTotal] [bigint] NOT NULL,
[SizeUsed] [bigint] NOT NULL,
[PercentageUsed] [int] NOT NULL
)
TABLE [Aggregate](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[UUID] [uniqueidentifier] NOT NULL,
[Name] [nvarchar](255) NOT NULL,
[Cluster_UUID] [uniqueidentifier] NOT NULL,
[DiskTypeID] [int] NOT NULL
)
TABLE [DiskType](
[Id] [int] IDENTITY(1,1) NOT NULL,
[TypeName] [nvarchar](255) NULL
)
TABLE [Volume](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[UUID] [uniqueidentifier] NOT NULL,
[Name] [nvarchar](255) NOT NULL,
[Aggregate_UUID] [uniqueidentifier] NOT NULL,
[ServiceClassID] [int] NULL,
[ProtocolID] [int] NOT NULL,
[EnvironmentID] [int] NOT NULL
)
TABLE [VolumeData](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Volume_UUID] [uniqueidentifier] NOT NULL,
[DataDate] [date] NOT NULL,
[SizeAvailable] [bigint] NOT NULL,
[SizeTotal] [bigint] NOT NULL,
[SizeUsed] [bigint] NOT NULL,
[PercentageUsed] [int] NOT NULL
)
Now in the end I need to get the following data:
DataDate, DiskType, AggregateSizes (Avail, Used, Total), Aggregated Volume Sizes (Sum of Avail, Used, Total of Volumes in that Aggregate)
I was thinking of using subqueries but when trying to get the values for a specific Aggregate only (for testing, easier for my to check) I get wrong values in the subquery.
Here is what I tried;
SELECT
AggregateData.DataDate,
AggregateData.SizeTotal AS AggregateSizeTotal,
(SELECT
SUM(VolumeData.SizeTotal)
FROM VolumeData
LEFT JOIN Volume
ON VolumeData.Volume_UUID = Volume.UUID
WHERE Aggregate_UUID = Volume.Aggregate_UUID
AND VolumeData.DataDate = AggregateData.DataDate)
VolumeSizeTotal
FROM AggregateData
WHERE AggregateData.Aggregate_UUID = 'C58D0098-D1A4-4EE9-A0E9-7DE3EEB6275C'
ORDER BY AggregateData.DataDate
But this seems me to not get the correct value for the subquery sum. My subquery sum is way to high so I assume my where clause is incorrect (or the whole setup ;) ...)
So, question 1. Are subqueries the way to go or should I do it differently?
If (question 1 == true) Whats wrong with my subquery?
You need to qualify all column names. I would recommend using table abbreviations. The problem is Aggregate_UUID = v.Aggregate_UUID. The first column is coming from v so this is (essentially) a no-op.
Presumably, you want this correlated with the outer query:
SELECT ad.DataDate, ad.SizeTotal AS AggregateSizeTotal,
(SELECT SUM(vd.SizeTotal)
FROM VolumeData vd LEFT JOIN
Volume v
ON vd.Volume_UUID = v.UUID
WHERE ad.Aggregate_UUID = v.Aggregate_UUID AND
ad.DataDate = vd.DataDate
) VolumeSizeTotal
FROM AggregateData ad
WHERE ad.Aggregate_UUID = 'C58D0098-D1A4-4EE9-A0E9-7DE3EEB6275C'
ORDER BY ad.DataDate
You can do this using JOIN instead of correlated subquery (O(n^2) performance) -
SELECT
t1.DataDate,
t1.SizeTotal AS AggregateSizeTotal,
t2.total VolumeSizeTotal
FROM AggregateData t1 left join (SELECT
DataDate, SUM(VolumeData.SizeTotal) total
FROM VolumeData
LEFT JOIN Volume
ON VolumeData.Volume_UUID = Volume.UUID
WHERE Aggregate_UUID = Volume.Aggregate_UUID
group by DataDate) t2 on t1.datadate = t2.dataDate
WHERE t1.Aggregate_UUID = 'C58D0098-D1A4-4EE9-A0E9-7DE3EEB6275C';
Going for a query to return the desired end results, I would use something like this:
Now in the end I need to get the following data: DataDate, DiskType, AggregateSizes (Avail, Used, Total), Aggregated Volume Sizes (Sum of Avail, Used, Total of Volumes in that Aggregate)
select
AggregateUuid = a.uuid
, DiskType = dt.TypeName
, DataDate = ad.DataDate
, AggregateSizeAvailable = ad.SizeAvailable
, AggregateSizeUsed = ad.SizeUsed
, AggregateSizeTotal = ad.SizeTotal
, VolumeSizeAvailable = sum(vd.SizeAvailable)
, VolumeSizeUsed = sum(vd.SizeUsed)
, VolumeSizeTotal = sum(vd.SizeTotal)
from [Aggregate] a
inner join DiskType dt on dt.Id = a.DiskTypeId
inner join AggregateData ad on ad.Aggregate_uuid = a.uuid
left join Volume v on v.Aggregate_uuid = a.uuid
left join VolumeData vd on vd.Volume_uuid = v.uuid
and vd.DataDate = ad.DataDate
where a.uuid = 'C58D0098-D1A4-4ee9-A0E9-7de3eeb6275C'
group by
a.uuid
, dt.TypeName
, ad.DataDate
, ad.SizeAvailable
, ad.SizeUsed
, ad.SizeTotal
order by a.uuid, ad.DataDate;
test setup: http://rextester.com/HZZHLI45077
create table DiskType(
Id int identity(1,1) not null
, TypeName nvarchar(255) null
);
set identity_insert DiskType on;
insert into DiskType (Id, TypeName) values
(1,'Type1'), (2,'Type2');
set identity_insert DiskType off;
create table [Aggregate](
Id bigint identity(1,1) not null
, uuid uniqueidentifier not null
, Name nvarchar(255) not null
, Cluster_uuid uniqueidentifier not null
, DiskTypeid int not null
);
insert into [Aggregate] (uuid, name, cluster_uuid, disktypeid)
select 'C58D0098-D1A4-4EE9-A0E9-7DE3EEB6275C', 'ex', newid(), 1;
create table AggregateData(
Id bigint identity(1,1) not null
, Aggregate_uuid uniqueidentifier not null
, DataDate date not null
, SizeAvailable bigint not null
, SizeTotal bigint not null
, SizeUsed bigint not null
, PercentageUsed int not null
);
insert into AggregateData
select 'C58D0098-D1A4-4EE9-A0E9-7DE3EEB6275C', '20170101', 12,100,87,87
union all select 'C58D0098-D1A4-4EE9-A0E9-7DE3EEB6275C', '20170102', 9,100,90,90
union all select 'C58D0098-D1A4-4EE9-A0E9-7DE3EEB6275C', '20170103', 6,100,93,93;
create table Volume(
Id bigint identity(1,1) not null
, uuid uniqueidentifier not null
, Name nvarchar(255) not null
, Aggregate_uuid uniqueidentifier not null
, ServiceClassid int null
, Protocolid int not null
, Environmentid int not null
);
insert into Volume
select '00000000-0000-0000-0000-000000000001', 'v1'
, 'C58D0098-D1A4-4EE9-A0E9-7DE3EEB6275C', null, 1, 1
union all select '00000000-0000-0000-0000-000000000002', 'v2'
, 'C58D0098-D1A4-4EE9-A0E9-7DE3EEB6275C', null, 1, 1
union all select '00000000-0000-0000-0000-000000000003', 'v3'
, 'C58D0098-D1A4-4EE9-A0E9-7DE3EEB6275C', null, 1, 1;
create table VolumeData(
Id bigint identity(1,1) not null
, Volume_uuid uniqueidentifier not null
, DataDate date not null
, SizeAvailable bigint not null
, SizeTotal bigint not null
, SizeUsed bigint not null
, PercentageUsed int not null
);
insert into VolumeData
select '00000000-0000-0000-0000-000000000001', '20170101', 4,33,29,88
union all select '00000000-0000-0000-0000-000000000002', '20170101', 4,33,29,88
union all select '00000000-0000-0000-0000-000000000003', '20170101', 4,34,29,87
union all select '00000000-0000-0000-0000-000000000001', '20170102', 3,33,30,91
union all select '00000000-0000-0000-0000-000000000002', '20170102', 3,33,30,91
union all select '00000000-0000-0000-0000-000000000003', '20170102', 3,34,30,90
union all select '00000000-0000-0000-0000-000000000001', '20170103', 2,33,31,94
union all select '00000000-0000-0000-0000-000000000002', '20170103', 2,33,31,94
union all select '00000000-0000-0000-0000-000000000003', '20170103', 2,34,31,93
go
/* -------------------------------------------------------- */
select
AggregateUuid = a.uuid
, DiskType = dt.TypeName
, DataDate = convert(varchar(10),ad.DataDate,121)
, AggregateSizeAvailable = ad.SizeAvailable
, AggregateSizeUsed = ad.SizeUsed
, AggregateSizeTotal = ad.SizeTotal
, VolumeSizeAvailable = sum(vd.SizeAvailable)
, VolumeSizeUsed = sum(vd.SizeUsed)
, VolumeSizeTotal = sum(vd.SizeTotal)
from [Aggregate] a
inner join DiskType dt on dt.Id = a.DiskTypeId
inner join AggregateData ad on ad.Aggregate_uuid = a.uuid
left join Volume v on v.Aggregate_uuid = a.uuid
left join VolumeData vd on vd.Volume_uuid = v.uuid
and vd.DataDate = ad.DataDate
where a.uuid = 'C58D0098-D1A4-4ee9-A0E9-7de3eeb6275C'
group by
a.uuid
, dt.TypeName
, ad.DataDate
, ad.SizeAvailable
, ad.SizeUsed
, ad.SizeTotal
order by a.uuid, ad.DataDate;
results in:
+--------------------------------------+----------+------------+------------------------+-------------------+--------------------+---------------------+----------------+-----------------+
| AggregateUuid | DiskType | DataDate | AggregateSizeAvailable | AggregateSizeUsed | AggregateSizeTotal | VolumeSizeAvailable | VolumeSizeUsed | VolumeSizeTotal |
+--------------------------------------+----------+------------+------------------------+-------------------+--------------------+---------------------+----------------+-----------------+
| c58d0098-d1a4-4ee9-a0e9-7de3eeb6275c | Type1 | 2017-01-01 | 12 | 87 | 100 | 12 | 87 | 100 |
| c58d0098-d1a4-4ee9-a0e9-7de3eeb6275c | Type1 | 2017-01-02 | 9 | 90 | 100 | 9 | 90 | 100 |
| c58d0098-d1a4-4ee9-a0e9-7de3eeb6275c | Type1 | 2017-01-03 | 6 | 93 | 100 | 6 | 93 | 100 |
+--------------------------------------+----------+------------+------------------------+-------------------+--------------------+---------------------+----------------+-----------------+
Related
CREATE TABLE #temppayload(
[user_id] [int] NOT NULL,
[field_id] [int] NOT NULL,
[type_id] [int] NOT NULL,
[field_value_string] [nvarchar](4000) NULL,
[field_value_numeric] [float] NULL,
[field_value_date] [date] NULL,
[field_value_bool] [bit] NULL,
[field_value_lookup] [int] NULL
)
insert into #temppayload values (1,31,1,'NEW',NULL,NULL,NULL,NULL)
insert into #temppayload values (1,11,1,'Update1',NULL,NULL,NULL,NULL)
insert into #temppayload values (1,12,2,NULL,NULL,NULL,NULL,'4')
insert into #temppayload values (4,41,4,Null,'1',NULL,NULL,NULL)
CREATE TABLE #tempdb(
[user_id] [int] NOT NULL,
[field_id] [int] NOT NULL,
[type_id] [int] NOT NULL,
[field_value_string] [nvarchar](4000) NULL,
[field_value_numeric] [float] NULL,
[field_value_date] [date] NULL,
[field_value_bool] [bit] NULL,
[field_value_lookup] [int] NULL
)
insert into #tempdb values (1,11,1,'create1',NULL,NULL,NULL,NULL)
insert into #tempdb values (1,12,2, NULL,NULL,NULL,NULL,NULL)
insert into #tempdb values (1,13,3,NULL,NULL,'2020-04-15',NULL,NULL)
insert into #tempdb values (4,41,4,NULL,'1',NULL,NULL,NULL)
user_id field_id type_id [field_value_string] [field_value_numeric] [field_value_date] [field_value_bool] [field_value_lookup]
1 31 1 NEW NULL NULL NULL NULL
1 11 1 update1 NULL NULL NULL NULL
1 12 2 NULL NULL NULL NULL 4
1 13 3 NULL NULL NULL NULL NULL
condition
new value from payload
value change compared to payload and tempdb
insert with null when #temppayload does not have it but exist in #tempdb
i was thinking of doing not exist seperately, left join seperately and union both the result.
Adding condition like below , the approach does not look efficient to me. i tried with innerjoin and leftjoin together could not figure out.
Any help is much appreciated . Thanks in advance.
select
distinct
st.user_id
,st.field_id
,st.type_id
,st.field_value_string
,st.field_value_numeric
,st.field_value_date
,st.field_value_bool
,st.field_value_lookup
from #temppayload st
where not exists (select *
from #tempdb t
where st.user_id = t.user_id
AND st.type_id = t.type_id
AND st.field_id = t.field_id
AND st.field_value_string = t.field_value_string
AND st.field_value_string IS NULL
AND t.field_value_string Is NULL
Able to figure this out by below approach . feel free to share if there is any other efficient way to do this.
select * into #modifiedpayload FROM
(select distinct st.user_id,st.field_id,st.type_id,st.field_value_string,st.field_value_numeric,st.field_value_date,st.field_value_lookup from
#temppayload st
where not exists (select user_id,st.field_id,st.type_id,st.field_value_string,field_value_numeric from #tempdb
where st.user_id = user_id
AND st.type_id = type_id
AND st.field_id = field_id
AND (st.field_value_string IS NULL AND field_value_string IS NULL OR st.field_value_string = field_value_string)
AND (st.field_value_numeric IS NULL AND field_value_numeric IS NULL OR st.field_value_numeric = field_value_numeric)
AND (st.field_value_date IS NULL AND field_value_date IS NULL OR st.field_value_date = field_value_date)
AND (st.field_value_bool IS NULL AND field_value_bool IS NULL OR st.field_value_bool = field_value_bool)
AND (st.field_value_lookup IS NULL AND field_value_lookup IS NULL OR st.field_value_lookup = field_value_lookup)
)
UNION
select t.user_id,t.field_id,t.type_id, NULL as field_value_string, NULL as field_value_numeric, NULL as field_value_date, NULL field_value_lookup from #tempdb t
LEFT JOIN #temppayload s
on t.user_id = s.user_id AND t.field_id = s.field_id
where s.field_id IS NULL ) AS X
I have this query:
CREATE TABLE [factOffertDetail](
[idOffertRow] [INT] IDENTITY(1,1) NOT NULL,
[idOffertRegion] [INT] NOT NULL,
[idProduct] [INT] NOT NULL,
[Qty] [DECIMAL](12, 2) NULL,
[idUnitPrice] [TINYINT] NULL
)
DECLARE #TMP2 TABLE (
idOffertRowNEW INT,
idOffertRow INT
)
INSERT INTO factOffertDetail
( idOffertRegion ,
idProduct ,
Qty ,
idUnitPrice
)
OUTPUT inserted.idOffertRow INTO #TMP2(d.idOffertRowNEW)
SELECT
d.idOffertRegion,
d.idProduct ,
d.Qty ,
d.idUnitPrice
FROM factOffertDetail d
I need to get the keys of the old and the new idOffertRow generated by identity.
idOffertRow is the identity (1,1) key of the factOffertDetail table.
How can I do this with an insert ?
Is it possible or I have to switch to merge command ?
Thanks to support
I would recommend to doing this:
Alter your table with new coloum,
ALTER TABLE [factOffertDetail]
ADD [ParentId] [INT] NULL
then,
INSERT INTO factOffertDetail
( ParentId,
idOffertRegion ,
idProduct ,
Qty ,
idUnitPrice
)
OUTPUT inserted.idOffertRow,inserted.ParentId INTO #TMP2(idOffertRowNEW,idOffertRow)
SELECT
d.idOffertRow,
d.idOffertRegion,
d.idProduct ,
d.Qty ,
d.idUnitPrice
FROM factOffertDetail d
Thank You!
I have simple table which puzzles me:
CREATE TABLE [dbo].[T3]
(
[id] [int] IDENTITY(1,1) NOT NULL,
[S_Id] [int] NULL,
[P_Id] [int] NULL,
[level] [int] NULL,
[Path] [nvarchar](255) NULL
) ON [PRIMARY]
In the table is data
id S_Id P_Id level Path
------------------------------------
1 218252 218231 1 218231
2 218271 218252 1 218252
3 218271 218252 2 218231-218252
EDIT:
I try to get the
ID, S_ID, P_ID, level, Path
on maximum length of column Path.
It should return id 3.
If I try to get max len from path like this:
select
b.id, a.p_id, a.s_id,
max(len(a.path)) as Path,
a.path
from
t3 a, t3 b
where
b.id = a.id
group by
a.p_id , a.s_id, b.id , a.path
order by
1
I get all the data, not just row with id 3, why ?
If you only want the max path record... Correct me if I'm wrong.
;WITH tmp AS (select TOP 1 id from #TaskTask3 ORDER BY LEN(path) DESC)
select t.*
from #TaskTask3 t
inner join tmp on tmp.id = t.id
Updates
;WITH tmp AS (select id, row_number() over (partition by S_Id, P_Id order by len(path) DESC) as rn from #TaskTask3)
select t.*
from #TaskTask3 t
inner join tmp on tmp.id = t.id
WHERE tmp.rn = 1
I tried to keep it simple....There are other methods (mentioned already) but I think you need to start slow... :)
declare #maxLen int
select #maxLen = max(len(path))
from t3
select * from t3
where len (path) = #maxLen
To put weePee's answer in a simple way,you can use the following query:
select id,s_id,p_id,level from t3 where len(path)= (select max(len(path)) from t3)
This is what I used to create and insert into table t3:
CREATE TABLE [dbo].[T3]
(
[id] [int] IDENTITY(1,1) NOT NULL,
[S_Id] [int] NULL,
[P_Id] [int] NULL,
[level] [int] NULL,
[Path] [nvarchar](255) NULL
) ON [PRIMARY]
insert into t3 (s_id,p_id,level,path) values (218252,218231,1,'218231'),(218271,218252,1,'218252'),(218271,218252,2,'218231-218252')
I have created a dummy scenario that reflect many of the queries I have to write to check that some data we are importing is correct.
The example would be when you have 3 tables
Store
Customer
CustomerOrder
A Customer can belong to many stores but can only 1 OrderOnsale can be bought x customer x store.
Cannot seem to get it right. Below is tables and noddy data + my attempt.
IF object_id(N'Store', 'U') IS NOT NULL
DROP TABLE Store
GO
CREATE TABLE [dbo].[Store]
(
[Id] [bigint] NOT NULL,
[StoreName] [varchar](50) NOT NULL,
CONSTRAINT [PK_Store] PRIMARY KEY CLUSTERED ([Id] ASC)
) ON [PRIMARY]
GO
IF object_id(N'Customer', 'U') IS NOT NULL
DROP TABLE Customer
GO
CREATE TABLE [dbo].[Customer]
(
[CustomerId] [bigint] NOT NULL,
[StoreId] [bigint] NOT NULL,
[Name] [varchar](50) NOT NULL,
[Surname] [varchar](50) NOT NULL,
CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED ([CustomerId] ASC)
) ON [PRIMARY]
GO
IF object_id(N'CustomerOrder', 'U') IS NOT NULL
DROP TABLE CustomerOrder
GO
CREATE TABLE [dbo].[CustomerOrder]
(
[OrderId] [bigint] NOT NULL,
[CustomerId] [bigint] NOT NULL,
[OrderName] [varchar](50) NOT NULL,
[OnSale] [bit] NOT NULL,
CONSTRAINT [PK_CustomerOrder] PRIMARY KEY CLUSTERED([OrderId] ASC)
) ON [PRIMARY]
GO
begin tran
INSERT INTO [dbo].[Store]([Id], [StoreName])
SELECT 1, N'Harrods' UNION ALL
SELECT 2, N'John Lewis'
INSERT INTO [dbo].[Customer]([CustomerId], [StoreId], [Name], [Surname])
SELECT 1, 1, N'John', N'Smith' UNION ALL
SELECT 2, 2, N'Joe', N'Blogg'
INSERT INTO [dbo].[CustomerOrder]([OrderId], [CustomerId], [OrderName], [OnSale])
SELECT 1, 1, N'Toys', 1 UNION ALL
SELECT 2, 1, N'Laptop', 1 UNION ALL
SELECT 3, 2, N'Toys', 0
commit
My incomplete attempt:
SELECT
HasCustomerBoughtMoreThanO1ItemOnSale =
CASE WHEN Count(T2.TotalBoughtOnSale) > 1 THEN 1 ELSE 0 END
FROM
CustomerOrder co1
INNER JOIN
customer c1 ON co1.CustomerId = c1.CustomerId
INNER JOIN
STORE S01 ON C1.StoreId = S01.Id
JOIN
(SELECT
CO2.CustomerId, S2.Id AS StoreId,
Count(CO2.OnSale) TotalBoughtOnSale
FROM
CustomerOrder CO2
INNER JOIN
customer c2 ON c2.CustomerId = CO2.CustomerId
INNER JOIN
STORE S2 ON C2.StoreId = S2.Id
WHERE
CO2.OnSale = 1
GROUP BY
CO2.CustomerId, S2.Id) AS t2 ON c1.CustomerId = T2.CustomerId
AND S01.Id = t2.StoreId
If what your after is if a single customer has bought more then one OnSale item then this query will do the trick.
SELECT
CO.CustomerId, C.StoreId
FROM CustomerOrder CO
INNER JOIN Customer C ON CO.CustomerId = C.CustomerId
WHERE OnSale = 1
GROUP BY CO.CustomerId, C.StoreId
HAVING COUNT(*) > 1
I should add that in this its given that a Customer can only shop in a single Store due to StoreId is a column in the Customer table.
select case when exists(
select top 1 1
from dg_world_records wr (nolock)
where wr.gametypeid = 4
and wr.playerid = 1
)
then totaltime = (select min(totaltime) from dg_world_records (nolock) where playerid = 1 and gametypeid = 4)
else totaltime = (select max(totaltime) from dg_world_records (nolock) where gametypeid = 4)
end
My guess is that this can't be done, but I'm trying to do a subselect within a sql case statement. Is this possible?
I'm trying to do a lookup based of finding or not finding a value in a table. I can do this by breaking up the statement, but I was wondering if it's possible to do this in a single statement.
Here is the table schema:
CREATE TABLE [dbo].[DG_WORLD_RECORDS](
[WorldRecordId] [int] IDENTITY(1,1) NOT NULL,
[GameTypeId] [int] NOT NULL,
[PlayerId] [int] NOT NULL,
[NumberOfValues] [int] NOT NULL,
[TotalTime] [int] NOT NULL,
[DateOfRecord] [datetime] NOT NULL,
[GameId] [int] NULL,
[UTCInserted] [datetime] NOT NULL CONSTRAINT [DF_DG_WORLD_RECORDSII_UTCInserted] DEFAULT (getutcdate()),
[UTCUpdated] [datetime] NOT NULL CONSTRAINT [DF_DG_WORLD_RECORDSII_UTCUpdated] DEFAULT (getutcdate()),
[SrvName] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_DG_WORLD_RECORDSII_SrvName] DEFAULT (##servername),
CONSTRAINT [PK_DG_WORLD_RECORDS] PRIMARY KEY CLUSTERED
(
[WorldRecordId] ASC
)
)
Don't know why you are writing this crazy query, but to answer your question, yes it could be done, just move your assignment out of the case statement:
select totaltime = CAST (
case when exists(
select *
from dg_world_records wr (nolock)
where wr.gametypeid = 4 and wr.playerid = 1)
then (select min(totaltime) from dg_world_records (nolock) where playerid = 1 and gametypeid = 4)
else (select max(totaltime) from dg_world_records (nolock) where gametypeid = 4)
end AS INT)