-- as for index... the simplest is:
create index idx_phone_id1_id2 on names (phone,id1,id2);
--emulating setting up parameter string - additional quotes because it is SQL
declare @param varchar(max)
set @param = '''991234567'',''991234568'',''991234569'''
select @param -- show the real string value required as a parameter list
exec uGetNames @param -- how it is called - exec is optional interactively
Create procedure uGetNames @Phonelist varchar(max)
as
begin
declare @sqlcmd varchar(max)
--have to create as a sqlcmd because of string inclusions
set @sqlcmd = 'SELECT Name '+
'FROM Names '+
'WHERE ID1 = 2 '+
'AND ID2 = 1 '+
'AND Phone in ('+@phonelist+')'
exec(@sqlcmd)
end
|