Hi all,
I have a table as -
| ID | Code | Value |
| 1 | 101 | abc |
| 2 | 101 | def |
| 3 | 201 | abc |
| 4 | 101 | def |
Now,
In this table, I need to check the uniqueness in combination -
101 - abc ---> allowed.
101 - def ---> allowed.
101 - def ->> NOT ALLOWED.... Combination "101 - def" exists.
Similarly,
Combination "101 - abc" must not be allowed next time.
How to check this combination uniqueness in SQL Server ??
Please help !!
Pankaj Kumar ChoudharyPosted Jun 2, 2015, 7:11 AM
as
(
Select Id,Code,value, ROW_NUMBER() Over(partition by Code , Value order By Code) as Row1
from Table_name
)
Select * from CTE where Row1>1
sudipta sanyalPosted Jun 2, 2015, 7:06 AM
Pankaj Kumar ChoudharyPosted Jun 2, 2015, 7:03 AM
Instead Of Insert
as
Begin
Declare @Code int
Declare @value nvarchar(max)
select @Code= tab.Code from inserted tab
select @value= tab.value from inserted tab
IF NOT EXISTS (SELECT * FROM table_name WHERE code = @Code AND value = @value)
BEGIN
INSERT INTO Table_name
VALUES (@Code,@value)
END
End
Riddhi ValechaPosted Jun 2, 2015, 6:47 AM
sudipta sanyalPosted Jun 2, 2015, 6:35 AM