Files
DP44/DataPRO_sql/dbo.Alter_foo_GetIdenticalChannelCount.sql
2026-04-17 14:55:32 -04:00

34 lines
1.7 KiB
Transact-SQL
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
USE [DataPRO]
GO
/****** Object: UserDefinedFunction [dbo].[foo_GetIdenticalChannelCount] Script Date: 4/2/2019 2:40:54 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[foo_GetIdenticalChannelCount]
(
@GroupId1 int,
@GroupId2 int
)
RETURNS int
AS
BEGIN
return (
SELECT COUNT(*)
FROM [dbo].[Channels] C1,
[dbo].[Channels] C2
WHERE C1.GroupId = @GroupId1
AND C2.GroupId = @GroupId2
AND ((C1.SensorId IS NULL AND C2.SensorId IS NULL) OR (C1.SensorId = C2.SensorId))
AND C1.IsoCode = C2.IsoCode
AND C1.IsoChannelName = C2.IsoChannelName
AND C1.UserCode = C2.UserCode
AND C1.UserChannelName = C2.UserChannelName
AND (C1.DASId IS NULL OR C2.DASId IS NULL OR C1.DASId = C2.DASId)
AND (C1.DASId IS NULL OR C2.DASId IS NULL OR C1.DASChannelIndex = C2.DASChannelIndex)
)
END