Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings, i've a table with records:

C#
----------------------------------
ID   |  UniqueId |  Name  | Result
----------------------------------
1       1           Test1   OK
2       1           Test1   Cancelled
3       1           Test1   OK
4       2           Test2   OK
5       2           Test2   OK
6       2           Test2   OK
7       2           Test2   OK
8       3           Test3   OK
9       3           Test3   OK


Let's say i wan't to check if at least one row with UniqueId = 1 not contains Result == Cancelled.
How can i do this?
Thank you
Posted
Updated 28-Aug-14 20:35pm
v2
Comments
syed shanu 29-Aug-14 2:48am    
check liks this

SELECT * FROM TABLENAME
WHERE
(UniqueId IN (1) AND Result NOT IN ('Cancelled'))
Zoltán Zörgő 29-Aug-14 2:50am    
Please clarify the condition: you want to check if among all rows with a specific UniqueId there is no row where Result=Cancelled? Which would be false in case of UniqueId=1 but true in case of UniqueId=2 and UniqueId=3. This is what you want?

You can use this
SQL
Select * from TableName Where UniqueId = 1 AND Result <> 'Cancelled'
 
Share this answer
 
You want to know if any test with that unique id was cancelled?

Well if you use something like a bit you can read it as boolean and it would be true=1, which yields something you can refine with a where more and put in a stored procedure if you like



declare @tbl table(
	id int,
	uniqueid int,
	name nvarchar(10),
	result nvarchar(20)
)

insert into @tbl(id, uniqueid, name, result)
values(1,1, 'Test1', 'OK')
insert into @tbl(id, uniqueid, name, result)
values(2,1, 'Test1', 'Cancelled')
insert into @tbl(id, uniqueid, name, result)
values(4,2, 'Test2', 'OK')
insert into @tbl(id, uniqueid, name, result)
values(5,2, 'Test1', 'OK')


select a.uniqueid, case when a.result = 'Cancelled' then 1 else 0 end wascancelled
from 
(select distinct uniqueid, min(Result) result
from @tbl
group by uniqueid) a
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900