블로그 이미지
010-9967-0955 보미아빠

카테고리

보미아빠, 석이 (500)
밥벌이 (16)
싸이클 (1)
일상 (1)
Total
Today
Yesterday

달력

« » 2024.3
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

공지사항

최근에 올라온 글

--dynamic 쿼리가 몹시 귀찮은 경우
--다른 컬럼으로 index 를 타고, 필터조건만 처리 할 경우 유용한 쿼리 로직

if object_id ('tblx') is not null
drop table tblx
go

create table tblx
(idx int
,c1 int
,c2 int
)
go

insert into tblx values(1,1,null),(2,null,2),(3,3,3), (4, null,null)

-- @c1 의 값이 null 이면 필터하지 않고, 값이 있으면 값으로 뿌린다.
-- 보통 다음과 같은 쿼리를 짜는데, 이는 null 값에 문제를 일으킨다.
-- 아래 문제를 해결하는 것이 미션 1 이다.

declare @c1 int = null

select *
  from tblx
 where c1 = case when @c1 is null then c1 else @c1 end
go

-- 해결방안

declare @c1 int = null

select *
  from tblx
 where (c1 = @c1 or 1=case when @c1 is null  then 1 else 0 end)
go

-- @c1 의 값이 9999 이면 필터하지 않고, 값이 있으면 값으로 출력하며, null 이면 null 만 출력한다. 
-- 이것이 미션 2 이다.

declare @c1 int = 9999

select *
  from tblx
 where (c1 = @c1 or 1=case when @c1 = 9999  then 1 else 0 end) or (c1 is null and 1=case when @c1 is null then 1 else 0 end)
go

-- 복합 필터 조건
declare @c1 int = null
declare @c2 int = null

select *
  from tblx
 where ((c1 = @c1 or 1=case when @c1 = 9999  then 1 else 0 end) or (c1 is null and 1=case when @c1 is null then 1 else 0 end))
   and ((c2 = @c2 or 1=case when @c2 = 9999  then 1 else 0 end) or (c2 is null and 1=case when @c2 is null then 1 else 0 end))
go

 select *
  from tbly
 where (a = @col1 or @col1 is null)

Posted by 보미아빠
, |

미시령 업힐~

카테고리 없음 / 2011. 4. 17. 23:07

난 평소 로드를 타면서 헬멧을 쓰지 않았다.
그런데 이날 대회라서 어쩔수 없이 헬멧을 착용했다. 그런데, 다운힐 후 시속 50 ~ 60 KM 로 달리는 상황에서 그 말로만 듣던 낙차를 할뻔 했다. 이날 바람이 어찌나 심하게 불던지 정말 휙 밀리더니 넘어질뻔 했다. 온몸에 식은땀.......
이날 이후는 헬멧을 꼭 착용한다. 봄이도 있고 여름이도 곧 나올 준비를 하고, 혹시나 낙차해 침 흘리고 살 수 없지 않는가...

Posted by 보미아빠
, |

EXEC sp_change_users_login 'Update_One', 'loginname', 'loginname'

create login loginname with password = 'password'
go

use northwind
go

create user loginname for login loginname
go

GRANT EXECUTE TO loginname
go

EXEC master..sp_dropsrvrolemember @loginame = N'coupon', @rolename = N'sysadmin'
EXEC master..sp_addsrvrolemember @loginame = N'coupon', @rolename = N'sysadmin'

에러는 이렇게 잡으세요~

create proc a
with execute as owner
as

select 'dynamic sql'
go





Denali ?
Denali 에서는 아래와 같은 기능이 추가 되었습니다.

Custom server roles

Mike Walsh blog post: http://bit.ly/AB_Denali_MikeWalsh
Posted by 보미아빠
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함