Check duplicate names in SQL server table

Posted by Nandkishorrech under Sql Server on 8/28/2017 | Points: 10 | Views : 755 | Status : [Member] | Replies : 6
Hi all,
i have below table like this.
id name class
1 A null
2 B null
3 c null
4 d null
1 A 9
3 c 9

how to check data with bit value is exist or not. i need below output.

i tried this... but not working
SELECT Id,name,class
(case when isnull(class,123)=123 then 0 else 1 end) as exist
FROM test_Table.

i need below output
id name class exist
2 B null 0
4 d null 0
1 A 9 1
3 c 9 1

regards
Kishore




Responses

Posted by: Bandi on: 8/29/2017 [Member] [MVP] Platinum | Points: 25

Up
0
Down
declare @tab table(id int, name char(1),class int)
insert @tab
select 1, 'A', null union all
select 2 , 'B' ,null union all
select 3 , 'c' ,null union all
select 4 , 'd' ,null union all
select 1 , 'A' ,9union all
select 3 , 'c' ,9

SELECT Id,name, max(class) class, case when count(class) >=1 then 1 else 0 end as IsExists
FROM @tab
GROUP BY id, name

output
Id	name	class	IsExists
1 A 9 1
2 B NULL 0
3 c 9 1
4 d NULL 0


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Nandkishorrech, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anujarishimehta on: 12/20/2017 [Member] Starter | Points: 25

Up
0
Down
Will the below query help?

Select Id, name, Class, 0 as Exists
from test_Table
where class is null
union all
Select Id, name, Class, 1 as Exists
from test_Table
where class is not null

Thanks & Regards,

Nandkishorrech, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kerrywin89 on: 12/20/2017 [Member] Starter | Points: 25

Up
0
Down
Not so long ago, essay writing required many hours of sitting in a library, studying multiple sources of information, and then rewriting the text by hand. Now, of course, the task is facilitated by the ability to find information on the Internet and just copying it, but to look for this information, and structuring and proofreading text, still takes time. In addition, considering the abundance of data on the worldwide web, you can’t always be sure of information's authenticity. https://rocketpaper.net/buy-essay-online


Nandkishorrech, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandeepmhatre on: 12/27/2017 [Member] Starter | Points: 25

Up
0
Down
there are different ways to check the duplicate rows in sql server
one of the way can be explained on this link
http://sandeepmhatre.blogspot.in/2012/10/delete-duplicate-rows-in-sql-server-2005.html

Sandeep M,
Software Developer
Follow me on :
http://sandeepmhatre.blogspot.in

Nandkishorrech, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kerrywin89 on: 12/27/2017 [Member] Starter | Points: 25

Up
0
Down
Some people identify the fact that when one intends to buy college term paper is a highly undesired outcome of the plenitude of activities in which the students are involved. Most of the students work part-time jobs, and this complicates their situation in the sense that they need certain outside help in completing their term papers. That is why some of them tend to buy custom term papers to ease their life. Therefore, they begin to search for a suitable company providing extensive custom term paper services, a place where they offer custom term papers to buy from. The phenomenon that provokes the students to buy term paper has received great attention recently since the appearance of fake custom term paper companies claiming their false pretenses and guarantees for quality. One thing is clear: the students need to be more attentive when they want to buy term paper, considering a series of important factors (the company must offer APA, MLA, Chicago and Turabian style term papers to buy) including the origin and the qualifications of the respective term paper writers who prepare custom term papers for the customers. https://rocketpaper.net/buy-college-term-paper

Nandkishorrech, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kirthiga on: 5/17/2018 [Member] Starter | Points: 25

Up
0
Down
SELECT Id,name,max(class) class,case when count(class)>=1 then 1 else 0 end Ex FROM TableName GROUP BY id, name

Nandkishorrech, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response