2007년 12월 13일 목요일

[MS-SQL] 조건에 따라 Insert 와 Update..

MS-SQL에서 IF문을 이용해 name이란 값을 받아서,

name에 해당하는 날짜에 값이 있으면 Update 없으면 Insert 한다.


[code type=sql] IF (select count(cnt)
     from t_count
     where convert(char(10), getdate(), 120) = regdate
     and pageName='name'
   ) > 0

   BEGIN
        update t_count set pagecnt = pagecnt+1 where pageName='name'
    END

   ELSE
     BEGIN
        insert into t_count values(convert(char(10), getdate(), 120), 'name', 1)     
    END[/code]

댓글 없음:

댓글 쓰기