Reputation: 152
i have one Schedule Table like
i want to look like select query data is:
1 and 11 is Duplicate trainer and Duplicate day,time
10 and 12 is Duplicate trainer, Duplicate vanueid and Duplicate date,time
so last two column are display is not Duplicate than available and is Duplicate than display notavailable
Upvotes: 1
Views: 56
Reputation: 4550
Here is the solution that is coming to my mind.There may some syntax issue but i given the logic which may help you.
DECLARE @duplicate TABLE (
trainerId INT,
dt varchar(50)
)
INSERT INTO @duplicate SELECT TrainerId , [Date] from tbl GROUP BY TrainerId , Date HAVING (COUNT(*) > 1)
SELECT * FROM @duplicate
DECLARE @tempTable TABLE (
trainerId INT,
dt varchar(50),
status int
)
INSERT INTO @tempTable
SELECT trainerId , [Date] , STATUS = (SELECT COUNT(*) FROM @duplicate where trainerId = tbl.TrainerId and dt = tbl.Date) FROM tbl
![enter image description here][2]SELECT * , CASE [status] WHEN 0 THEN 'Available' ELSE 'Not Available' END FROM @tempTable
Upvotes: 1