SQLÓï¾äµÄÌí¼Ó¡¢É¾³ý¡¢ÐÞ¸ÄËäÈ»ÓÐÈçϺܶàÖÖ·½·¨£¬µ«ÔÚʹÓùý³ÌÖл¹ÊDz»¹»Ó㬲»ÖªÊÇ·ñÓиßÊְѸü¶àÁé»îµÄʹÓ÷½·¨¹±Ï׳öÀ´£¿
Ìí¼Ó¡¢É¾³ý¡¢ÐÞ¸ÄʹÓÃConnection.Execute (Sql)ÃüÁîÖ´ÐвÙ×÷
¨X----------------¨[
¡î Êý¾Ý¼Ç¼ɸѡ ¡î
¨^----------------¨a
×¢Ò⣺µ¥Ë«ÒýºÅµÄÓ÷¨¿ÉÄÜÓÐÎó(ûÓвâʽ)
Sql = "Select Distinct ×Ö¶ÎÃû From Êý¾Ý±í"
Distinctº¯Êý£¬²éѯÊý¾Ý¿â´æ±íÄÚ²»Öظ´µÄ¼Ç¼
Sql = "Select Count(*) From Êý¾Ý±í where ×Ö¶ÎÃû1>#18:0:0# and ×Ö¶ÎÃû1< #19:00# "
countº¯Êý,²éѯÊý¿â±íÄÚÓжàÉÙÌõ¼Ç¼£¬¡°×Ö¶ÎÃû1¡±ÊÇָͬһ×Ö¶Î
Àý£º
set rs=conn.execute("select count(id) as idnum from news")
response.write rs("idnum")
sql="select * from Êý¾Ý±í where ×Ö¶ÎÃû between Öµ1 and Öµ2"
Sql="select * from Êý¾Ý±í where ×Ö¶ÎÃû between #2003-8-10# and #2003-8-12#"
ÔÚÈÕÆÚÀàÊýֵΪ2003-8-10 19:55:08 µÄ×Ö¶ÎÀï²éÕÒ2003-8-10ÖÁ2003-8-12µÄËùÓмǼ£¬¶ø²»¹ÜÊǼ¸µã¼¸·Ö¡£
select * from tb_name where datetime between #2003-8-10# and #2003-8-12#
×Ö¶ÎÀïÃæµÄÊý¾Ý¸ñʽΪ£º2003-8-10 19:55:08£¬Í¨¹ýsql²é³ö2003-8-10ÖÁ2003-8-12µÄËùÓмͼ£¬¶ø²»¹ÜÊǼ¸µã¼¸·Ö¡£
Sql="select * from Êý¾Ý±í where ×Ö¶ÎÃû=×Ö¶ÎÖµ order by ×Ö¶ÎÃû [desc]"
Sql="select * from Êý¾Ý±í where ×Ö¶ÎÃû like '%×Ö¶ÎÖµ%' order by ×Ö¶ÎÃû [desc]"
Ä£ºý²éѯ
Sql="select top 10 * from Êý¾Ý±í where ×Ö¶ÎÃû order by ×Ö¶ÎÃû [desc]"
²éÕÒÊý¾Ý¿âÖÐÇ°10¼Ç¼
Sql="select top n * form Êý¾Ý±í order by newid()"
Ëæ»úÈ¡³öÊý¾Ý¿âÖеÄÈô¸ÉÌõ¼Ç¼µÄ·½·¨
top n£¬n¾ÍÊÇҪȡ³öµÄ¼Ç¼Êý
Sql="select * from Êý¾Ý±í where ×Ö¶ÎÃû in ('Öµ1','Öµ2','Öµ3')"
¨X----------------¨[
¡î Ìí¼ÓÊý¾Ý¼Ç¼ ¡î
¨^----------------¨a
sql="insert into Êý¾Ý±í (×Ö¶Î1,×Ö¶Î2,×Ö¶Î3 ¡) valuess (Öµ1,Öµ2,Öµ3 ¡)"
sql="insert into Êý¾Ý±í valuess (Öµ1,Öµ2,Öµ3 ¡)"
²»Ö¸¶¨¾ßÌå×Ö¶ÎÃû±íʾ½«°´ÕÕÊý¾Ý±íÖÐ×ֶεÄ˳Ðò£¬ÒÀ´ÎÌí¼Ó
sql="insert into Ä¿±êÊý¾Ý±í select * from Ô´Êý¾Ý±í"
°ÑÔ´Êý¾Ý±íµÄ¼Ç¼Ìí¼Óµ½Ä¿±êÊý¾Ý±í
Conn.Execute sqlÓï¾ä
ͨ¹ýconnection ¶ÔÏóµÄ Execute·½·¨Ìí¼Ó¼Ç¼
¨X----------------¨[
¡î ¸üÐÂÊý¾Ý¼Ç¼ ¡î
¨^----------------¨a
Sql="update Êý¾Ý±í set ×Ö¶ÎÃû=×Ö¶ÎÖµ where Ìõ¼þ±í´ïʽ"
Sql="update Êý¾Ý±í set ×Ö¶Î1=Öµ1,×Ö¶Î2=Öµ2 ¡¡ ×Ö¶În=Öµn where Ìõ¼þ±í´ïʽ"
Sql="update Êý¾Ý±í set ×Ö¶Î1=Öµ1,×Ö¶Î2=Öµ2 ¡¡ ×Ö¶În=Öµn "
ûÓÐÌõ¼þÔò¸üÐÂÕû¸öÊý¾Ý±íÖеÄÖ¸¶¨×Ö¶ÎÖµ
Conn.Execute sqlÓï¾ä
ͨ¹ýconnection ¶ÔÏóµÄ Execute·½·¨¸üмǼ
¨X----------------¨[
¡î ɾ³ýÊý¾Ý¼Ç¼ ¡î
¨^----------------¨a
Sql="delete from Êý¾Ý±í where Ìõ¼þ±í´ïʽ"
Sql="delete from Êý¾Ý±í"
ûÓÐÌõ¼þ½«É¾³ýÊý¾Ý±íÖÐËùÓмǼ)
Conn.Execute sqlÓï¾ä
ͨ¹ýconnection ¶ÔÏóµÄ Execute·½·¨É¾³ý¼Ç¼
¨X--------------------¨[
¡î Êý¾Ý¼Ç¼ͳ¼Æº¯Êý ¡î
¨^--------------------¨a
AVG(×Ö¶ÎÃû) µÃ³öÒ»¸ö±í¸ñÀ¸Æ½¾ùÖµ
COUNT(*|×Ö¶ÎÃû) ¶ÔÊý¾ÝÐÐÊýµÄͳ¼Æ»ò¶ÔijһÀ¸ÓÐÖµµÄÊý¾ÝÐÐÊýͳ¼Æ
MAX(×Ö¶ÎÃû) È¡µÃÒ»¸ö±í¸ñÀ¸×î´óµÄÖµ
MIN(×Ö¶ÎÃû) È¡µÃÒ»¸ö±í¸ñÀ¸×îСµÄÖµ
SUM(×Ö¶ÎÃû) °ÑÊý¾ÝÀ¸µÄÖµÏà¼Ó
ÒýÓÃÒÔÉϺ¯ÊýµÄ·½·¨£º
sql="select sum(×Ö¶ÎÃû) as ±ðÃû from Êý¾Ý±í where Ìõ¼þ±í´ïʽ"
set rs=conn.execute(sql)
Óà rs("±ðÃû") »ñȡͳµÄ¼ÆÖµ£¬ÆäËüº¯ÊýÔËÓÃͬÉÏ¡£
¨X----------------------¨[
¡î Êý¾Ý±íµÄ½¨Á¢ºÍɾ³ý ¡î
¨^----------------------¨a
Create TABLE Êý¾Ý±íÃû³Æ(×Ö¶Î1 ÀàÐÍ1(³¤¶È),×Ö¶Î2 ÀàÐÍ2(³¤¶È) ¡¡ )
Àý£ºCreate TABLE tab01(name varchar(50),datetime default now())
Drop TABLE Êý¾Ý±íÃû³Æ (ÓÀ¾ÃÐÔɾ³ýÒ»¸öÊý¾Ý±í)
¨X--------------------¨[
¡î ¼Ç¼¼¯¶ÔÏóµÄ·½·¨ ¡î
¨^--------------------¨a
rs.movenext ½«¼Ç¼ָÕë´Óµ±Ç°µÄλÖÃÏòÏÂÒÆÒ»ÐÐ
rs.moveprevious ½«¼Ç¼ָÕë´Óµ±Ç°µÄλÖÃÏòÉÏÒÆÒ»ÐÐ
rs.movefirst ½«¼Ç¼ָÕëÒƵ½Êý¾Ý±íµÚÒ»ÐÐ
rs.movelast ½«¼Ç¼ָÕëÒƵ½Êý¾Ý±í×îºóÒ»ÐÐ
rs.absoluteposition=N ½«¼Ç¼ָÕëÒƵ½Êý¾Ý±íµÚNÐÐ
rs.absolutepage=N ½«¼Ç¼ָÕëÒƵ½µÚNÒ³µÄµÚÒ»ÐÐ
rs.recordcount ·µ»Ø¼Ç¼×ÜÊý
rs.bof ·µ»Ø¼Ç¼ָÕëÊÇ·ñ³¬³öÊý¾Ý±íÊ׶ˣ¬true±íʾÊÇ£¬falseΪ·ñ
rs.eof ·µ»Ø¼Ç¼ָÕëÊÇ·ñ³¬³öÊý¾Ý±íÄ©¶Ë£¬true±íʾÊÇ£¬falseΪ·ñ
rs.delete ɾ³ýµ±Ç°¼Ç¼£¬µ«¼Ç¼ָÕë²»»áÏòÏÂÒƶ¯
rs.addnew Ìí¼Ó¼Ç¼µ½Êý¾Ý±íÄ©¶Ë
rs.update ¸üÐÂÊý¾Ý±í¼Ç¼