You are on page 1of 24

SQL..........................................................................................................

2
1 SQL .............................................................................................................................................................2
2 ..................................................................................................................................................2
3 ..............................................................................................................................................................................3
4 SQL .....................................................................................................................................................4

SQL EXPRESSION..........................................................................................6
1

SQL EXPRESSION ARCMAP ................................................................................................................6

1.1

.........................................................................................................................................................6

1.1.1 (Extract)................................................................................................................................................................6
1.1.2 (Conversion).......................................................................................................................................................6
1.1.3 ...............................................................................................................................................................................7

1.2

.........................................................................................................................................................7

1.2.1 ...............................................................................................................................................................................7
1.2.2 ...............................................................................................................................................................................8

1.3

.........................................................................................................................................................8

1.3.1 Layer ...................................................................................................................................................................8


1.3.2 Model Builder.............................................................................................................................................................9
1.3.3 (Linear Referencing)..................................................................................................................................9

SQL EXPRESSION ...........................................................................................................................................10

2.1

-..................................................................................................................................10

2.2

-..........................................................................................................11

2.3

"and" "or".............................................................................................................................................11

2.4

"in" "not in"..........................................................................................................................................11

2.5

SQL ..............................................................................................................................................12

2.6

Null................................................................................................................................................................12

2.7

(From MS Access Help)................................................................................................................13

2.8

sql ................................................................................................................................................14

FIELD CALCULATOR SQL ......................................................15


1 SQL DLBM DLBM1...............................................................................................................15
2 - DLBM1 DLMC1.................................................................................17
3 .............................................................................18

VBE ADO SQL..................................................................21


1

ADO CONNECTION.......................................................................................................................................21

SQL (UPDATE)...............................................................................................................................22

................................................................................................................................23
(lucy11149@163.com)
(tj051181@gmail.com)

ESRI
--- ArcMap SQL
SQL(Structured Query Language)

SQL SQL
ArcMap SQL

SQL
SQL SQL
SQL 4
1 (DDL)CREATEDROPALTER
2 (DML)INSERTUPDATEDELETE
3 (DQL)SELECT
4 (DCL)GRANTREVOKECOMMITROLLBACK
ArcMap 23 select

1 SQL
select * from table1 where
insert into table1(field1,field2) values(value1,value2)
delete from table1 where
update table1 set field1=value1 where
select * from table1 where field1 like %value1% ---like !
select * from table1 order by field1,field2 [desc]
select count as totalcount from table1
select sum(field1) as sumvalue from table1
select avg(field1) as avgvalue from table1
select max(field1) as maxvalue from table1
select min(field1) as minvalue from table1

2
1UNION
UNION TABLE1 TABLE2
ALL UNION UNION ALL
TABLE1 TABLE2
(lucy11149@163.com)
(tj051181@gmail.com)

2EXCEPT
EXCEPT TABLE1 TABLE2
ALL EXCEPT (EXCEPT ALL)
3 INTERSECT
INTERSECT TABLE1 TABLE2
ALL INTERSECT (INTERSECT ALL)

3
1. INNER JOIN 2. LEFT JOIN

3. RIGHT JOIN 4.LEFT OUTER JOIN

ID

NAME

ID

CLASS

IBM

C1

SONY

C3

BMW

C4

1 INNER JOIN: SELECT * FROM

INNER JOIN B ON A.ID=B.ID

ID

NAME

CLASS

IBM

C1

BMW

C3

ID
2 LEFT JOIN : SELECT * FROM

LEFT JOIN B ON A.ID=B.ID

ID

NAME

CLASS

IBM

C1

SONY

null

BMW

C3

A(left ) B
3

RIGHT JOIN :

SELECT * FROM

RIGHT JOIN B ON A.ID=B.ID

RIGHT()

ID

NAME

CLASS

IBM

C1

BMW

C3

null

C4

B(right ) A

4 FULL OUTER JOIN:

SELECT * FROM

FULL OUTER JOIN B ON A.ID=B.ID

ID

NAME

CLASS

IBM

C1
(lucy11149@163.com)
(tj051181@gmail.com)

SONY

null

BMW

C3

null

C4

4 SQL
mysql access
1(,a b) (Access )
select * into b from a where 1<>1
select top 0 * into b from a
2(,a b) (Access )
insert into b(a, b, c) select d,e,f from b;
3() (Access )
insert into b(a, b, c) select d,e,f from b in where
insert into b(a, b, c) select d,e,f from [].b where
..from b in "&Server.MapPath(".")&"\data.mdb" &" where..
4( 1a 2b)
select a,b,c from a where a IN (select d from b ) : select a,b,c from a where a IN (1,2,3)
5
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table
where table.title=a.title) b
6( 1a 2b)
select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
7( 1a )
select * from (Select a,b,c FROM a) T where t.a > 1;
8between ,between ,not between
select * from table1 where time between time1 and time2
select a,b,c, from table1 where a not between 1 and 2
9in
select * from table1 where a [not] in ( 1, 2, 4, 6)
10
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )
11
select * from a left inner join b on a.a=b.b right inner join c on a.a=c.c inner join d on a.a=d.d
where .....
12
select * from where datediff(minute,f ,getdate())>5
13 SQL
select top 10 b.* from (select top 20 , from order by desc) a,
(lucy11149@163.com)
(tj051181@gmail.com)

b where b. = a. order by a.
14 10
select top 10 * form table1 where
15 b a (
,,,.)
select a,b,c from tablename ta where a=(select max(a) from tablename tb where tb.b=ta.b)
16 TableA TableB TableC

(select a from tableA ) except (select a from tableB) except (select a from tableC)
17 10
select top 10 * from tablename order by rnd(id )
18
select rnd( id )
19
Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)
20
select name from sysobjects where type=U
21
select name from syscolumns where id=object_id(TableName)
22 typevenderpcs type case
select case
select type,sum(case vender when A then pcs else 0 end),sum(case vender when C
then pcs else 0 end),sum(case vender when B then pcs else 0 end) FROM tablename group by
type

type

vender

pcs

23 10 15
select top 5 * from (select top 15 * from table order by id asc) table_ order by id desc

ArcMap
ArcMap SQL

(lucy11149@163.com)
(tj051181@gmail.com)

SQL Expression
SQLArcMapSQL ExpressionESRI
SQL Reference

1 SQL ExpressionArcMap
SQL Expression

1.1

1.1.1 (Extract)
Query Builder

Select

Analysis\Extract

Table Select

Analysis\Extract

Extract by Attributes

Spatial\Analyst

Feature Class To Feature Class

Conversion\To Geodatabase

Table To Table

Conversion\To Geodatabase

CADLinestoPolygonFeatures

CAD

Samples\Conversion\To From CAD

1.1.2 (Conversion)

A. Feature Class To FeatureClass ArcToolbox ArcCatalog import\Feature


Class(Single)
B. CADLinestoPolygonFeatures ESRI Model Builder Model Query
Builder CAD
CAD polyline annotation layer
= xx
(lucy11149@163.com)
(tj051181@gmail.com)

1.1.3

Select By Attribut

Tools

Field Calculator

set Null

Spatial Analyst\Conditional

1.2

ArcMap SQL Expression


ArcMap Drawing Errors

[A] SQL Expression [A] = 1

1.2.1
Layer Properties\ Definition Query Distributed Geodatabase
Query Definition Query Get Cout

(lucy11149@163.com)
(tj051181@gmail.com)

1.2.2
Layer Properties\ Labels \ classes labels SQL Expression

Lable
http://bbs.esrichina-bj.cn/esri/viewthread.php?tid=55808

1.3

1.3.1 Layer
ArcGIS
layer 2

select layer by attribute

Tools\Select by Attribute

Layers and Table Views

Make Feature Layer

Make Query Table

(lucy11149@163.com)
(tj051181@gmail.com)

1.3.2 ModelBuilder
SQL Expression CAD polyline annotation
CAD Lines to Polygon Features (Samples) 1.1.2
SQL Expression Create Variable

1.3.3 (LinearReferencing)
Diligentpig ArcGIS /
http://bbs.esrichina-bj.cn/esri/viewthread.php?tid=56638

(lucy11149@163.com)
(tj051181@gmail.com)

2 SQLExpression

Select By Attribute Query Builder ArcGIS SQL


SELECT * FROM layer WHERE

SQL WHERE
.1

2.1 -
1 dltb dlbm 011
[DLBM] =011

2 dltb dlbm dlbm1


[DLBM] <> [DLBM1]
[] PGDB ArcGIS

(lucy11149@163.com)
(tj051181@gmail.com)

10

2.2 -
(1) dltb dlbm 01
Left(TRIM([dlbm]),2)=01

(2) dlmc
[dlmc] like **
Personal Geodatabase

shapefile

Function

Examples

Function

Examples

mod

[] mod 2 = 0

mod

mod("",2)=0

left

left([],2)="Ts"

substr

substr("",1,2)=Ts

mid

mid([],2,2)="so"

substr

substr("",2,2)=so

2 2

len

len([])= 4

char_length

char_length( "" ) = 4

instr

instr([],"o")=2

position

position(o in "") = 2

a A

[]="tsonghua"

lcase

lcase([])="tsonghua"

ucase
#wildcard#

#[]#

ucase([
])="TSONGHUA"
[] > 2 ; [] = "2"
[] like "2*" or []
like "?2"
[BIRTH] = #06-13-2001
19:30:00#

pGDB lower()
lower

lower("")=tsonghua

pGDB Lcase()

upper
#wildcard#

date

upper("
")=TSONGHUA
"" > 2 : "" = 2
"" like 2% or ""
like _2

pGDB []fGDB ""


* & ?

VS. % & _

"BIRTH" = date 2001-06-13

pGDB #fGDB

19:30:00

date

PGDB shp

http://bbs.esrichina-bj.cn/esri/viewthread.php?tid=60118

2.3 "and" "or"


1 dlbm 011 dlmc
[dlbm]=0110 and [dlmc] =
2 dlbm 011 dlmc
[dlbm]=0110 or dlmc =

2.4 "in" "not in"


1 dlbm 011001200130
(lucy11149@163.com)
(tj051181@gmail.com)

11


[dlbm]= 011 or [dlbm]= 012 or [dlbm]= 013
in
[dlbm] in (011, 012,013)
in not in

2.5 SQL
1 10
[OBJECTID]

in (select top 10 [OBJECTID] from dltb order by rnd( [OBJECTID] ) )

2 OBJECTID 11 15
[OBJECTID]

in

(select top 5 OBJECTID from (select top 15 * from dltb order by OBJECTID asc) b

order by OBJECTID desc)


2
1
[OBJECTID] not in (select max(OBJECTID) from dltb group by dlbm)
2
[dlbm] in (select dlbm from dltb group by dlbm having count(*) >1)
3 mdb
pgdb sql mdb mdb

[dlbm] in (select dlbm from [c:\tempdata.mdb].)


tempdata.mdb dlbm

http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=55857
sql
http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=53458

http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=54652

2.6 Null
<Null> "Null" ""0 Null
Null Null [] is Null [] = Null
(lucy11149@163.com)
(tj051181@gmail.com)

12

2.7 (From MS Access Help)


Like

? _

* %

(0 - 9)

[]

[!]

([ ])
ANSI ANSI Microsoft Windows 8
256 0 255ASCII ANSI ANSI Microsoft
Windows 8 256 0 255
ASCII
ANSI ([ )
(?) (#) (*) ( ])

(-)
[A-Z] A Z
[a-zA-Z0-9]

ANSI SQL (%) (_) Microsoft Access Microsoft


Office Access 2007 OLE DB Provider Microsoft Office Access 2007 DAO

1. (!)

2. (-)
ANSI
3.A-Z 0-100[A-Z] [Z-A]

4. [ ]
("
")
(" ") ("")

(lucy11149@163.com)
(tj051181@gmail.com)

13

LikeFrom MS Access Help

True

False

a*a

aaaBaaBBBa

aBC

*ab*

abcAABBXab

aZbbac

a[*]a

a*a

aaa

ab*

abcdefgabc

cabaab

a?a

aaaa3aaBa

aBBBa

a#a

a0aa1aa2a

aaaa10a

[a-z]

fpj

2&

[!a-z]

9&%

ba

[!0-9]

Aa&~

019

a[!b-m]#

An9az0a99

abcaj0

P A F
Like P[A-F]###

2.8 sql

[OBJECTID]

in (select objectid from

(select objectid, xzqdm as ,tbh as Dltbbh,dltb_xzdwmj as


,xzdw_mj as ,
iif(abs((dltb_xzdwmj-xzdw_mj))>0.0001,abs(dltb_xzdwmj-xzdw_mj),0) as DIfferent
from
(select a.objectid, a.zldwdm as xzqdm,a.xzdwmj as dltb_xzdwmj,a.tbbh as tbh,b.xzdwmj as
xzdw_mj from dltb a inner join
(select sum(xwmj) as xzdwmj,kctbbh1,kctbdwdm1 from
(SELECT sum(xzdwmj*kcbl) as xwmj,kctbbh1,kctbdwdm1 from xzdw
group by kctbbh1,kctbdwdm1
union all
SELECT sum(xzdwmj*(1-kcbl)) as xwmj,kctbbh2 as kctbbh1,kctbdwdm2 as kctbdwdm1 from xzdw
group by kctbbh2,kctbdwdm2
)group by kctbbh1,kctbdwdm1 order by kctbbh1) b
on a.zldwdm=b.kctbdwdm1 and a.tbbh=b.kctbbh1))
where abs(DIfferent)>0.0001 order by objectid)
SQL Expression

(lucy11149@163.com)
(tj051181@gmail.com)

14

Field CalculatorSQL
ArcGIS

SQL Field Calculator


SQL ExpressionESRI SQL
Field Calculator Field
Calculator AO AO SQL
Field Calculator

1 SQL dlbm dlbm1


IWorkspace Interface ExecuteSQL Method SQL Field Calculator

Field CalculatorSql
Field Calculator Flag
Model Builder
Make Feature Layer SQL Expression Calculate Field

(lucy11149@163.com)
(tj051181@gmail.com)

15

-------------------@ lucy1114 20100625


--------------------

static flag as long


if flag = 0 then
Dim pMxDoc As IMxDocument
Dim pDSName As IDatasetName
Dim i As Integer
Dim pdl2 As IDataLayer2
(lucy11149@163.com)
(tj051181@gmail.com)

16

Dim scommand
i = 0 0
Set pMxDoc = ThisDocument
Set pdl2 = pMxDoc.FocusMap.Layer(i)
Set pDSName = pdl2.DataSourceName
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pWorkspace As IWorkspace
Set pWorkspaceFactory = New AccessWorkspaceFactory
Set pWorkspace = pWorkspaceFactory.OpenFromFile(pDSName.WorkspaceName.PathName, 0)
-------------------------------------------------------

scommand = "update " & pDSName.name & " set dlbm1=dlbm"


-------------------------------------------------------

pWorkspace.ExecuteSQL scommand
flag = 1
end if
Field Calculator
SQL SQL

2 - dlbm1 dlmc1
scommand

(lucy11149@163.com)
(tj051181@gmail.com)

17

scommand = "update dltb left join on dltb.dlbm1=.dlbm set


dltb.dlmc1=.dlmc"

ArcGIS Desktop
http://bbs.esrichina-bj.cn/ESRI/thread-67896-1-3.html
SQL

(lucy11149@163.com)
(tj051181@gmail.com)

18

-------------------@ lucy1114 010625


--------------------

static flag as long


if flag = 0 then
Dim pMxDoc As IMxDocument
Dim pDSName As IDatasetName
Dim i As Integer
Dim pdl2 As IDataLayer2
Dim scommand
i = 0 0
Set pMxDoc = ThisDocument
Set pdl2 = pMxDoc.FocusMap.Layer(i)
Set pDSName = pdl2.DataSourceName
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pWorkspace As IWorkspace
Set pWorkspaceFactory = New AccessWorkspaceFactory
(lucy11149@163.com)
(tj051181@gmail.com)

19

Set pWorkspace = pWorkspaceFactory.OpenFromFile(pDSName.WorkspaceName.PathName, 0)


scommand ="Create TABLE temp_luys (fid_dltb long not null, mj double) "
pWorkspace.ExecuteSQL scommand
scommand = "Insert into temp_luys select fid_dltb,round(sum(iif(kcbl = 1,kd * Shape_Length, kd *
Shape_Length/2)),2) as mj from XZDW_Intersect group by fid_dltb"
pWorkspace.ExecuteSQL scommand
scommand = "update dltb left join temp_luys b on

dltb.OBJECTID_1=b.fid_dltb set

dltb.xzdwmj=b.mj"
pWorkspace.ExecuteSQL scommand
scommand = "DROP TABLE temp_luys"
pWorkspace.ExecuteSQL scommand
flag = 1
end if

Workspace

scommand = "update dltb set xzdwmj = dsum(iif(kcbl = 1,kd * Shape_Length, kd *


Shape_Length/2),XZDW_Intersect,fid_dltb= & dltb.OBJECTID)"

Field Calculator SQL


sql access sql

sql Sql

(lucy11149@163.com)
(tj051181@gmail.com)

20

VBEADOSQL
personal Geodatabase
MS Access personal Geodatabase Microsoft ActiveX Data
Objects 2.x SQL

ADO Connection

' --------------------------------------------------------------------------'ADO Connection


'ADO Recordset
'sql
'mdb Workspace
' ---------------------------------------------------------------------------

Public Cn As New ADODB.Connection


(lucy11149@163.com)
(tj051181@gmail.com)

21

Public Rs As ADODB.RecordSet
Public strSql As String
Public strMDBpath As String
' --------------------------------------------------------------------------'* : Cn
'* : mdbpath
'*

String

: Tsonghua

'* : 2010-06-26
' ---------------------------------------------------------------------------

Public Sub mdbConnection(mdbpath As String)


If VBA.Trim(mdbpath) <> "" Then
With Cn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & mdbpath & ";"
.CommandTimeout = 30
.CursorLocation = adUseClient
If Cn.State = 0 Then
.Open
End If
End With
Else
strLog = strLog & vbCrLf & "- ..."
Exit Sub
End If
End Sub

SQL (update)

' --------------------------------------------------------------------------'* : SQL Update


'* : mdbpath

String

'*

String

SQL

sql

'*

: Tsonghua

'* : 2010-06-26
' ---------------------------------------------------------------------------

Sub ExecuteSqlUpdate(ByVal strmdbpath As String, ByVal sql As String)


Call mdbConnection(strmdbpath)
Cn.Execute sql
(lucy11149@163.com)
(tj051181@gmail.com)

22

Cn.Close
End Sub

strSql = Update DLTB a , b set a.DLBM = b. where a.DLMC = b.


call ExecuteSqlUpdate(strSql)

' --------------------------------------------------------------------------'* : SQLSelect


'* : mdbpath
'*

sql

'*

String
String


SQL

: Tsonghua

'* : 2010-06-26
' ---------------------------------------------------------------------------

Function lngNull(ByVal sql As String, ByVal mdbpath As String) As Long


Call mdbConnection(mdbpath)
Set Rs = Cn.Execute(sql)
lngNull = Rs.RecordCount
Rs.Close
Cn.Close
End Function

Dim lngNullBSM As Long


strSql = select objectid from dltb where isnull(bsm) = true or bsm = 0
lngNullBSM= lngNull(strmdbpath,strSql)

(lucy11149@163.com)
(tj051181@gmail.com)

23

@Shanghai
6/26/2010 6:08:01 PM

(lucy11149@163.com)
(tj051181@gmail.com)

24

You might also like