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 2008 Forums
 Transact-SQL (2008)
 SQL Query Help

Author  Topic 

IK1972

56 Posts

Posted - 2012-09-12 : 14:22:13

I have one table suppose #temp with column ID.

If I have data like this then I should see 'Inside If'
ID
1
2
3

IF (select count(*) from #temp) > 1
print 'Inside If'
else
print 'Inside else'

If I have data like this
ID
1
2
2
3

then I should see 'Inside else'

basically I want to check base on Group ID.

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-12 : 14:48:28
it should be

IF (select count(*) from (select ID from #temp group by ID having count(*) > 1)t) > 1

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

IK1972

56 Posts

Posted - 2012-09-12 : 14:53:09

Yes, Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-12 : 14:55:06
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -