MS-SQL에서 얻어진 테이블에서 여러개의 결과값을 한 행에 표시하고 싶을때가 있습니다. 예를들어 
 강의명  강사
 국어 홍길동, 김영희 
 영어 김철수

이런식으로 여러개의 강사명을 한 row에 표시하려면
FOR XML 문을 편법으로 이용하면됩니다.

select 강좌명, 
(
select 강사명 + ', ' from 강사강의등록 as t1
inner join 강사 on 강사.강사코드 = 강사강의동록.강사코드
where t1.강좌명 = t2.강좌명
FOR XML path('')
)
as 강사리스트, 강의실 from 강사강의등록 as t2
inner join 강사 
on 강사.강사코드 = 강사강의동록.강사코드
group by 강좌명

Posted by leeyongwan
,
MySQL에서 특정 항목들을 제외시키고자할때 주로 사용하는 명령어가 NOT IN 입니다. 하지만 속도가 만족스럽지 못할때가 있습니다. 이때는 LEFT JOIN명령어를 사용해보세요.

예를 들어,
select * from cdr where calldate not in (
select calldate from cdr 
where disposition = 'ANSWERED')

의 경우는
다음과 같이 바꿀 수 있습니다.
select t1.calldate from cdr as t1 
left join (
select calldate from cdr 
where disposition = 'ANSWERED') as t2 
on t1.calldate=t2.calldate 
where t2.calldate is null 



Posted by leeyongwan
,
VB.NET에서 MySQL을 연결하여 사용하여야할 때가 있습니다. VB.NET을 어느정도 아신다고 가정하고 간단하게 설명해놓은 버전입니다.

1. MySQL Connector 를 설치합니다.


에서 ADO.NET Driver for MySQL 드라이버를 받아 설치합니다. 설치하면 
C:\Program Files\MySQL\MySQL Connector Net 6.2.4\Assemblies 폴더에 
MySql.Data.dll
파일이 생성됩니다.

2. 생성된 dll 파일을 레퍼런스에 추가합니다.

3. 코드를 다음과 같이 작성합니다.
Imports MySql.Data.MySqlClient

Dim MySQL_CS As String = "Server=111.111.111.111;" & _
"Database=dbname;Uid=id;Pwd=password;"
Dim SQL As String = "SELECT * FROM table1"
Dim myConn As New MySqlConnection(MySQL_CS)
Private myBindingSource As New BindingSource
Dim myCmd As New MySqlCommand

myCmd.Connection = myConn
myCmd.CommandText = SQL
myConn.Open()
Dim myReader As MySqlDataReader = myCmd.ExecuteReader

'table
myBindingSource.DataSource = myReader
DataGridView1.DataSource = myBindingSource
myConn.Close()



Posted by leeyongwan
,