Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
gfaryd
Starting Member
27 Posts |
Posted - 2011-04-15 : 05:49:07
|
| Dear All I have following table structure in sql 2000create table test (pid int,og_id int,remarks varchar(20))sample datainsert into test values (1,33,null)insert into test values (1,33,'account')insert into test values (1,44,null)insert into test values (2,13,null)insert into test values (2,31,'account')insert into test values (2,31,'something')insert into test values (2,31,null)insert into test values (2,31,null)in my scenario i want following out putpid og_id remarks1 33 account1 442 13 2 31 account2 31 somethingif remarks is null against same pid and og_id like in case of pid 1 and og_id 33 another row exist with pid 1 and og_id with remarks 'account' , i only need row without null. in case of pid 1 and og_id 44 remarks is null and no row exist having some remarks against these pid and og_id. so in short i want to omit those rows in which null remarks exist if another row is exist with not null so the output will be. 1 33 account1 44any help in queryRegards |
|
|
Ranjit.ileni
Posting Yak Master
183 Posts |
Posted - 2011-04-15 : 06:03:39
|
quote: in my scenario i want following out putpid og_id remarks1 33 account1 442 13 2 31 account2 31 something
with cte as(select pid, og_id, remarks from test where remarks is not nullunion allselect pid, og_id, remarks from test twhere not exists (select pid, og_id, remarks from test t1 where t.pid=t1.pid and t.og_id=t1.og_id and remarks is not null))select pid, og_id, remarks from cte order by pid --Ranjit |
 |
|
|
|
|
|
|
|