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
운영게시판
최근게시물
PostgreSQL Q&A 2527 게시물 읽기
No. 2527
Re: 필드가 같은 다른 테이블 검색????
작성자
정재익
작성일
2001-04-02 19:56
조회수
3,165

일단 쿼리를 해보고 없을 경우 다시 receptionold 에서 찾는 수 밖에 없을 것 같습니다. 아니면 만약 둘중하나에서 존재한다면 그냥 한꺼번에 두군데서 찾는 방법도 있을 것 같군요.

 

[ 1 의 방법 ]

:: $number = $cgi/>param('number');

:: if (length($number) == 6)

:: {

:: $cmd = qq! select * from reception where receptionno like '%$number' !;

:: }else{

:: $cmd = qq! select * from reception where receptionno='$number' !;

::

:: }

위의 구문을 이렇게 해야 할 것 같습니다.

$number = $cgi/>param('number');

if (length($number) == 6)

{

$cmd = qq! select * from reception where receptionno like '%$number' !;

}else{

$cmd = qq! select * from reception where receptionno='$number' !;

 

}

$result = $Pg/>query($cmd);

if (!$result) {

if (length($number) == 6)

{

$cmd = qq! select * from receptionold where receptionno like '%$number' !;

}else{

$cmd = qq! select * from receptionold where receptionno='$number' !;

}

}

$result = $Pg/>query($cmd);

 

이런식으로 하면 해결되지 않을까요.

 

[ 2의 방법 ]

:: $number = $cgi/>param('number');

:: if (length($number) == 6)

:: {

:: $cmd = qq! select * from reception where receptionno like '%$number' !;

:: }else{

:: $cmd = qq! select * from reception where receptionno='$number' !;

::

:: }

위의 구문을 다음과 같이 바꾸면 되지 않을까 싶습니다.

$number = $cgi/>param('number');

if (length($number) == 6)

{

$cmd = qq! select * from reception where receptionno like '%$number'

union

select * from receptionold where receptionno like '%$number' !;

}else{

$cmd = qq! select * from reception where receptionno = '%$number'

union

select * from receptionold where receptionno = '$number' !;

}

 

물론 두번째 구문은 그 결과값이 굳이 reception 에 있는지 receptionold 에 있는것인지 알필요가 없을 경우에 가능한 방법입니다. 참조하시기 바랍니다.

 

>>이준영 님께서 쓰시길<<

 

:: 안녕하세요

:: 저는 서비스센터에서 서버를 관리하는 사람인데요...

:: 전에 근무하시던 분이 하나의 테이블을 두개로 나눠 놓았습니다.

:: 하나는 reception 이고 다른 하나는 receptionold 거든요 문제는

:: 사용자에게 "접수번호"를 입력 받아서 테이블을 검색할때

:: reception테이블만 검색을 한다는 것입니다.

:: 먼저 reception에서 검색을 하고 없으면 receptionold에서 검색하는

:: 방법은 없을까여? 제발 도와주세요 아래쿼리문을 어떻게 고치면 될까요....

:: (참고로 perl로 작성된 프로그램입니다.)

::

:: $number = $cgi/>param('number');

:: if (length($number) == 6)

:: {

:: $cmd = qq! select * from reception where receptionno like '%$number' !;

:: }else{

:: $cmd = qq! select * from reception where receptionno='$number' !;

::

:: }

[Top]
No.
제목
작성자
작성일
조회
2533pg_shadow에 대하여 질문드립니다.
성은
2001-04-03
2812
2535┕>Re: pg_shadow에 대하여 질문드립니다.
주효식
2001-04-03 14:42:58
3020
2531안녕하세요? ODBC에서 질문이 있습니다.
calm1004
2001-04-03
3217
2530[질문]pg_log를 어디에 쓰지요?
임헌
2001-04-02
3065
2526필드가 같은 다른 테이블 검색????
이준영
2001-04-02
3013
2527┕>Re: 필드가 같은 다른 테이블 검색????
정재익
2001-04-02 19:56:36
3165
2524CREATE FUNCTION에 관하여.. 물어봅니다
김대성
2001-04-02
2947
2529┕>Re: CREATE FUNCTION에 관하여.. 물어봅니다
nogadax
2001-04-02 20:08:02
3103
2532 ┕>Re: Re: 노가다액스님께 평소에 감사의 말을 전하고 싶었습니다.
김대성
2001-04-03 11:08:01
2973
2534  ┕>Re: Re: Re: 노가다액스님께 평소에 감사의 말을 전하고 싶었습니다.
nogadax
2001-04-03 14:22:46
3079
2522Windows용 psql설치 정보
박성민
2001-04-02
3481
2528┕>Re: Windows용 psql설치 정보
정재익
2001-04-02 20:06:37
3269
2520기존의 pgsql에서 my sql을 설치 하려고 합니다.
김인태
2001-04-02
3299
2521┕>Re: 기존의 pgsql에서 my sql을 설치 하려고 합니다.
정재익
2001-04-02 10:18:09
3382
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.017초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다