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)
 shorter optimized version of following query

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2014-03-28 : 04:23:59
please suggests smaller version of following query.I have myself done but not able to recall

if( @id = 0 )
begin
select Count(*)
from [dbo].[event_attendee]
where email = @email
and eventid = @eventid
and coordinatorid = @coordinatorid
End
else
begin
select Count(*)
from [dbo].[event_attendee]
where email = @email
and ( id <> @id )
and eventid = @eventid
and coordinatorid = @coordinatorid
end


Kamran Shahid
Principle Engineer Development
(MCSD.Net,MCPD.net)

MuralikrishnaVeera
Posting Yak Master

129 Posts

Posted - 2014-03-28 : 04:35:43
SELECT CASE WHEN ID<>@id THEN COUNT(*)
WHEN @Id =0 THEN COUNT(*)
END
FROM [dbo].[event_attendee]
WHERE email = @email
AND eventid = @Eventid
AND Coordinateorid = @coordinatorId


---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page
   

- Advertisement -