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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Check if there is more than one record. Thanks.

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2006-12-05 : 13:59:00
Hello,

I am writing a SQL procedure and I need to check if in MyTable there is only one record where field [NAME] = @Name or if there is more then one.

How can I do this?

Thanks,
Miguel

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-12-05 : 14:16:33
select count(*) from MyTable where [NAME] = @Name
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-06 : 10:59:52
To find all names having more than one record

select Name,count(*) from MyTable
Group by Name
Having count(*)>1

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -