아래 저장프로시저를 만들었습니다.
색깔로 표시된 부분에 유의해서 볼때
주황색으로 표시된 부분의 조건을 바꾸어서 하고 싶은데
특히 'and Ttype=@Ttype' 이 부분만 따로 떼어서 조건문으로
하고 싶습니다.
Ttype의 값이 있으면 검색 조건에 넣고 없으면 검색조건에서 빠지는
겁니다.
몇 가지 해 보았는데, 잘 안되는군요..
고수님의 손길을 부탁드립니다.
create proc ctl_multiboard
@page int = NULL, @rowcount int = null, @Ttype char(2) = null,
@sFlag int = null, @sValue char(2) = null
as
declare @selcount int, @startrownum int, @endrownum int
select @selcount = @rowcount * @page
select @startrownum = (@page - 1) * @rowcount + 1
select @endrownum = @page * @rowcount
SET ROWCOUNT @selcount
SELECT rownum=identity(4),
writeno,title,username,password,email,content,readcnt,regdate,parentwriteno,founderwriteno,replydepth,replyorder,userip,gubun,appendflag,filetitle,filename,Ttype
INTO #ctl_board_temp FROM ctl_board
WHERE writeno <> 0 and Ttype=@Ttypeorder by founderwriteno desc, replyorder asc,
replydepth asc
SET ROWCOUNT 0
select
writeno,title,username,password,email,content,readcnt,regdate,parentwriteno,founderwriteno,replydepth,replyorder,userip,gubun,appendflag,filetitle,filename,Ttype
from #ctl_board_temp
where rownum >= @startrownum and rownum <= @endrownum
drop table #ctl_board_temp
|