database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
ㆍMS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
MS-SQL Q&A 5886 게시물 읽기
No. 5886
생일인사람에게 쿠폰주기
작성자
이종웅
작성일
2011-05-12 17:41ⓒ
2011-05-12 17:42ⓜ
조회수
6,931

도저히 실력이 딸려서 문의드립니다

쇼핑몰 작업중입니다. 오늘이 생일인 사람에게 생일쿠폰을 발급하는건데 프로시져로 만들어서 job으로 돌릴생각입니다.

아래와 같이 프로시져에서 쿠폰을 발급하는것까지는 했습니다만 이제 회원테이블에서 오늘이 생일자들을 가져와서 루프로 돌리면서

생일자의 아이디와 이름을 쿠폰테이블에 넣어야하는데 셀렉트한 후 루프를 어떻게 돌려서 넣어야할지 모르겠습니다. while문을 사용하는건지..

아울러 아래 방법이 아니라 더 좋은 간단한 방법이 있으면 더 좋구요.. 아래는 소스가 좀 기네요~~

alter proc birthday
As
if exists(select * from sl_coupon_kind where coupon_kind='생일쿠폰')
    declare @coupon_kind varchar(50)
    declare @coupon_name varchar(50)
    declare @coupon_price int
    declare @avail_kind varchar(50)
    declare @avail_price int
    declare @dc_kind varchar(50)
    declare @usedate_kind varchar(50)
    declare @sdate int
    declare @edate int
    declare @usedate_default varchar(50)
    declare @usedate int
    declare @usedate2 varchar(50)
    declare @payment_method varchar(50)

    select @coupon_kind = coupon_kind from sl_coupon_kind where coupon_kind='생일쿠폰'
    select @coupon_name = coupon_name from sl_coupon_kind where coupon_kind='생일쿠폰'
    select @coupon_price = coupon_price from sl_coupon_kind where coupon_kind='생일쿠폰'
    select @avail_kind = avail_kind from sl_coupon_kind where coupon_kind='생일쿠폰'
    select @avail_price = avail_price from sl_coupon_kind where coupon_kind='생일쿠폰'
    select @dc_kind = dc_kind from sl_coupon_kind where coupon_kind='생일쿠폰'
    select @usedate_kind = usedate_kind from sl_coupon_kind where coupon_kind='생일쿠폰'
    select @sdate = sdate from sl_coupon_kind where coupon_kind='생일쿠폰'
    select @edate = edate from sl_coupon_kind where coupon_kind='생일쿠폰'
    select @usedate_default = usedate_default from sl_coupon_kind where coupon_kind='생일쿠폰'
    select @usedate = usedate from sl_coupon_kind where coupon_kind='생일쿠폰'

    select @payment_method = payment_method from sl_coupon_kind where coupon_kind='생일쿠폰'
   

  begin  
    insert into sl_coupon(g_sitename,s_id,s_name,coupon_kind,coupon_name,coupon_price,avail_kind,avail_price,dc_kind,usedate_kind,sdate,edate,usedate_default,usedate,payment_method)
  values('aaaa','abcd','홍길동',@coupon_kind,@coupon_name,@coupon_price,@avail_kind,@avail_price,@dc_kind,@usedate_kind,@sdate,@edate,@usedate_default,convert(varchar(30),getdate()+@usedate,20),@payment_method)
 end 

이 글에 대한 댓글이 총 1건 있습니다.

대략 이런 식?

 

 ALTER PROC birthday
 AS
    ---'aaaa','abcd','홍길동 '이건 멤버 테이블에 있다고 가정..
    INSERT INTO  sl_coupon (g_sitename,s_id,s_name,coupon_kind,coupon_name,coupon_price,avail_kind,avail_price,dc_kind,usedate_kind,sdate,edate,usedate_default,usedate,payment_method)
    SELECT
        a.g_sitename, a.s_id, a.s_name
        , b.coupon_kind,b.coupon_name,b.coupon_price,b.avail_kind,b.avail_price,b.dc_kind,b.usedate_kind
        ,b.sdate,b.edate,b.usedate_default,convert(varchar(30),getdate()+b.usedate,20),b.payment_method
    FROM
        (SELECT * FROM  member WHERE 생일 = CONVERT(CHAR(8), GETDATE(), 112)) a ,  --대략 yyyymmdd라 가정
        (SELECT * FROM    sl_coupon_kind WHERE coupon_kind='생일쿠폰')  b
 
END

 

생일인 모든 회원에게 바로 데이터를 넣는...

생일이라는 칼럼은 인덱스를 ...

.님이 2011-05-13 14:58에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
58902008 r2 업그레이드 질문드립니다.
r2
2011-05-19
6069
5889급하게구합니다. mssql2000관리도구 도와주세요
김길동
2011-05-17
6201
5888ms-sql 질문 [1]
손헌희
2011-05-17
5832
5886생일인사람에게 쿠폰주기 [1]
이종웅
2011-05-12
6931
5885mssql function 만들 때 에러 [3]
기모노데쓰
2011-05-11
8901
5884mssql돌아가는데 에터프라이즈관리 프로그램? [4]
김길동
2011-05-10
6825
5882int형식으로 저장된 datetime값을 datetime형식으로 나타내고 싶을 때... [1]
이은규
2011-05-02
6241
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.018초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다