상세 컨텐츠

본문 제목

단위별 검색쿼리 만들기

청강컴정/DataBase

by luckey 2009. 6. 1. 17:22

본문

create function fn_get_where_divor
(
    @FLD nvarchar(70),
 @QS nvarchar(4000),
 @Div varchar(12),
 @KIND bit,
 @KEY nvarchar(36)
)
returns nvarchar(MAX)
as
begin
 declare @result nvarchar(max)
 declare @i int;
    declare @cnt_array int

 set @result = '('+@key +' IS NULL)';
 set @cnt_array = BoardSample.dbo.Get_Array_Item(@QS, -1, @DIV)

 set @i = 0
 
 if(@QS = '')
 begin
  if(@KIND = 0)
   SET @RESULT = '('+@key+' is NULL)'
  else
   SET @RESULT = '('+@key+' is not null)'
 end
 else
 begin
  while (@i < @cnt_array)
  begin
   set @result = @result + ' OR(' + @FLD + ' like''%' + rtrim(ltrim(BoardSample.dbo.Get_Array_Item(@QS, @i+1, @DIV))) + '%'')'
   set @i = @i + 1 
  end
 end
return @result
end

declare @where nvarchar(4000)
set @where = cafe_manage.dbo.fn_get_where_divor('name', '', ',',1, 'sn')
select @where
exec ('select * from member where ' + @where)

관련글 더보기

댓글 영역