SQLÖÐÈçºÎÓÃÒ»¸ö±í¸üÐÂÁíÒ»¸ö±í
for ACCESS :
update a, b set a.name=b.name1 where a.id=b.id
for SQL Server:
"update a set a.name=b.name1 from a,b where a.id=b.id"
update a set a.status=b.status
from table1 a,table2 b
where a.id1=b.id1
update a inner join b on a.a1=b.b1 set a.a2=b.b2Ìõ¼þ
update table1 set a.status = b.status
from table1 a inner join table2 b
on a.idl = b.idl
http://topic.csdn.net/t/20041013/14/3451961.html
http://www.cnblogs.com/hanguoji/archive/2007/02/01/636723.aspx
Ïà¹ØÎĵµ£º
¹ØÓÚÁ½±í¹ØÁªµÄupdate£¬µ«Óï¾äÔõôд¶¼²»ÕýÈ·£¬ÀÏÊDZ¨´í£¬ÓÚÊÇÐľªÈâÌø£¨¾ÍŲ»Äܼ°Ê±Íê³É²Ù×÷£©È¥²éÁËһϣ¬NND£¬ÔÀ´°ÑSQLд³ÉÁËÔÚSQL ServerÏÂÃæµÄÌØÓÐÐÎʽ£¬ÕâÖÖÓï·¨ÔÚOracleÏÂÃæÊÇÐв»Í¨µÄ£¬¼±Ã¦¸Ä»ØÀ´£¬¼°Ê±Íê³ÉÁËÈÎÎñ¡£Ë³±ãÒ²°Ñ²éµ½µÄSQLÌû³öÀ´£¬ÄÄÌìÔÙÍü¼ÇÁË£¬Ò²ºÃÔÚÕâÀïÕÒ»ØÀ´£º
update customers a ......
±íÖÐÖ÷¼ü±ØÐëΪ±êʶÁУ¬[ID] int IDENTITY (1,1)
1.·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)
Óï¾äÐÎʽ£º
SELECT TOP Ò³¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID NOT IN
(SELECT TOP (ÿҳÐÐÊý*(Ò³Êý-1)) ID
from ±íÃû
ORDER BY ID))
ORDER BY ID
//×Ô¼º»¹¿ÉÒÔ¼ÓÉÏһЩ²éѯ ......
TABLE MASTER ×ֶΠID DETAIL.....
TABLE BIZ ×ֶΠSYS_ID CODE_ID .......
²éѯʱÐèÒªµÄÊÇIDµÄÃèÊö
1,SELECT A.SYS_ID,A.CODE_ID,B.DETAIL,C.DETAIL...... from BIZ A,MASTER B,MASTER C WHERE A.SYS_ID=B.ID AND A.CODE_ID=C.ID
2,SELECT SYS_ID,(SELECT DETAIL from MASTER ......
----start
¶¯Ì¬SQLÊÇÔÚ³ÌÐòÔËÐÐʱ¹¹ÔìµÄ£¬ÒªÖ´Ðе¥ÌõSQL£¬Ê¹ÓÃEXECUTE IMMEDATE Óï¾ä£»µ±ÅúÁ¿Ö´ÐÐSQLʱ£¬ÏÈʹÓÃPREPARE Óï¾ä¹¹ÔìSQL£¬È»ºóʹÓÃEXECUTE Óï¾äÖ´ÐС£
Ò»£ºPrepareÓï¾ä£ºÓÃÀ´¹¹ÔìÅúÁ¿SQL
Óï·¨£º
PREPARE <sql-statement> [OUTPUT] INTO <result> [INPUT INTO] <input> ......
sql serverºÍoracleÐÐתÁеÄÒ»ÖÖµäÐÍ·½·¨
Ç°ÑÔ£ºÍøÉÏÓв»ÉÙÎÄÕÂÊǽ²ÐÐתÁеģ¬µ«ÊǴ󲿷ֶ¼ÊÇÖ±½ÓÌù´úÂ룬ºöÊÓÁËÖмä¹ý³Ì£¬±¾ÈË×Ô¼ºË¼¿¼ÁËÏÂΪʲôҪÕâÑùʵÏÖ£¬²¢ÇÒ×öÁËÈçϵıʼǣ¬¶ÔÓÐЩ¶®µÄÈËÀ´Ëµ¿ÉÄÜûÓмÛÖµ£¬Ï£Íû¶Ô»¹²»¶®µÄÈËÓÐÒ»µã½è¼øÒâÒå¡£
¶ÔÓÚÓÐЩҵÎñÀ´Ëµ£¬Êý¾ÝÔÚ±íÖеĴ洢ºÍÆä×îÖÕµÄGrid±íÏÖÇ¡ºÃÏ൱ÓÚ°ÑÔ ......