Is there a better way to write the SQL other than using the IN clause in the below given SP. When i am using this IN clause, i suffer a performance dip due to large number or records involved in the User and Member tables.
CREATE PROCEDURE [dbo].[sp_MemberIdsFromUserIds] @dtUserIds UNIQUETABLE readonly
AS
BEGIN
SELECT userID,
Memberid
FROM Member
INNER JOIN USER
ON UserMemberID = MemberiD
WHERE userID IN (SELECT UniqueId
FROM @dtUserIds)
END
Kindly suggest the alternative as i don't have a full knowledge in writing SP
@dtUserIds? – Martin Smith Dec 17 '12 at 10:12UNIQUETABLEtype? Do you have aprimary keyonuserID? Also you may be getting a bad plan due to cardinality estimates on the TVP. You could try withOPTION (RECOMPILE)to see if you get a plan better suited for 25K rows. – Martin Smith Dec 17 '12 at 10:29userIdare uniqueidentifier datatypes. I have userId as primary key in usertable and so with the case of memberid. shall i use theoption(recompile)in the stored procedure. – saravanan Dec 17 '12 at 14:22