SQL ×¢È붶´Ïà¹Ø֪ʶÕûÀí
ÉÏÉϸöÐÇÆÚ£¬ÓÐÈË·´À¡£¬CSDNÓÐSQL×¢È붶´£¬º¹ÑÕ£¬¼¸ÄêǰΪSQL×¢È붶´£¬²¿ÃÅרÃŶÔËùÓдúÂë×ö¹ýÒ»´Î·Ç³£´óµÄ¼ì²é£¬¾¹È»ÄǴμì²é»¹ÓÐÒÅ©µÄµØ·½¡£×î½üÕ⼸¸öÐÇÆÚ£¬¾ÍÊÇÒ»Ö±ÔÙ¶Ô´úÂë×öÔٴθ´²é£¬¿´ÓÐûÓÐSQL×¢È붶´¡£
´æÔÚSQL×¢È붶´£¬¾ÍÒòΪÄãµÄSQLÓï¾äÊÇ×Ô¼ºÆ´´ÕµÄ£¬ÔÚÆ´´ÕµÄʱºò£¬Ã»Óп¼ÂÇÓû§¿ÉÄÜÆ´´Õ½øÓÐÎÊÌâµÄÓï¾äÔì³ÉµÄ¡£
֮ǰÎÒÃDzÉÈ¥µÄ±ÜÃâ´ëÊ©ÊÇ£¬¶Ô½ÓÊܵIJÎÊýµÄУÑé½øÐзâ×°£¬ËùÓвÎÊýµÄ»ñµÃ£¬¶¼±ØÐëͨ¹ýÕâ¸ö·â×°µÄº¯ÊýÀ´»ñµÃ¡£µ«ÊÇʵ¼Ê¿ª·¢ÖУ¬×ÜÓÐЩµØ·½£¬ÓÐЩ´úÂëûÓе÷ÓÃÕâ¸ö·â×°µÄº¯ÊýÀ´½øÐÐУÑé¡£
ÉÏÖÜÄ©£¬¹«Ë¾ÄÚ²¿ÌÖÂÛ»áµÄʱºò£¬¾ö¶¨»»ÖÖ˼·¡£´Ó±ÜÃâ×Ô¼ºÆ´´ÕSQLÓï¾äµÄ·½Ê½À´ÊµÏÖ£¬¾ßÌå¾ÍÊÇ¿ª·¢¹æ·¶ÖÐÓÐÒ»Ìõ£¬²»ÔÊÐíÓÃÆ´´ÕµÄSQLÓï¾ä£¬Òª´«²ÎÊý£¬¾ÍÓÃSqlParameter¡£±ÈÈçÏÂÃæµÄ´úÂëÊDz»ÔÊÐíµÄ¡£
string strSQL = "select UserID,UserName,Email from User where UserName = '"+aa.replace("'","''")+"'";
SqlDataReader sdr = SqlHelper.ExecuteReader(strConnStr,CommandType.Text,strSQL)
¶øÏÂÃæµÄ´úÂëÊÇÔÊÐíµÄ£º
SqlParameter[] parm1 = new SqlParameter[]{
new SqlParameter("@UserName",SqlDbType.NVarChar,50)
};
parm1[0].Value = strUserName;
string strSQL = "select UserID,UserName,Email from user where UserName = @UserName ";
SqlDataReader sdr = SqlHelper.ExecuteReader(strConnStr,CommandType.Text,strSQL,parm1)
ÔÒò£ºSqlParameter »á×Ô¶¯´¦Àí²ÎÊýµÄУÑ飬¾ÍÀàËÆʹÓô洢¹ý³ÌÊDz»»á³öÏÖSQL×¢È붶´µÄÎÊÌâÒ»Ñù¡£
һЩSQL×¢ÈëÓйصÄ֪ʶµã£º
ÈçºÎSQL×¢È룺
http://www.54nb.com/Read.Asp?ID=1451672&Type=71
SQL×¢ÈëÖÐÓÐÓõļ¸¸öSQLÓï¾ä
[N] = µÚN個±í
ID=1 and (Select top 1 name from(Select top [N] id,name from sysobjects where xtype=char(85)) T order by id desc)>1
[T] = ±íÃû
[N] = µÚN個×Ö¶Î
ID=1 and (Select Top 1 col_name(object_id('[T]'),[N]) from sysobjects)>1
SQL×¢Èë±íÃûºÍ×Ö¶ÎÃûµÄ»ñµÃ
Ïà¹ØÎĵµ£º
1.Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)¡¡¡¡
¡¡¡¡ SQLSERVERµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬Òò´Ëfrom×Ó¾äÖÐдÔÚ×îºóµÄ±í£¨»ù´¡±ídriving table£©½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏ£¬±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í£¬µ±SQLSERVER´¦Àí¶à¸ö±íʱ£¬»áÔËÓÃÅÅÐò¼°ºÏ²¢µÄ·½Ê½Á ......
Õâ¸öº¯ÊýDateAdd(month,2,WriteTime)£º
ÈÕÆÚ²¿·ÖËõд Year yy, yyyy quarter qq, q Month mm, m dayofyear dy, y Day dd, d Week wk, ww Hour hh minute mi, n second ss, s millisecond ms
¡¡¡¡Õâ¸ö±í×㹻˵Ã÷ÎÊÌâÁË°É,´Óyearµ½millisecond¶¼¿ÉÒÔ´¦Àí£¬¹»·½±ãÁË°É.
DATEDIFF º¯Êý [ÈÕÆÚºÍʱ¼ä]
-------------- ......
ÔÚPL/SQLÖÐÒ²ÌṩGOTOÓï¾ä,ÆäÓï·¨ÊÇ
GOTO label;
ÕâÀïlabelÊÇÔÚPL/SQL¿éÖж¨ÒåµÄ±êÇ©.±êÇ©ÊÇÓÃË«¼ýÍ·À¨ºÅÀ¨ÆðÀ´µÄ.µ±Ö´ÐÐGOTOÓï¾äµÄʱºò,¿ØÖÆ»áÁ¢¼´×ªµ½ÓɱêÇ©±êʶµÄÓï¾ä.
1.¶ÔÓÚGOTOµÄÏÞÖÆ
a.¶ÔÓÚ¿é,Ñ»·»òÕßIFÓï¾ä¶øÑÔ,ÏëÒª´ÓÍâ²ãÌøµ½ÄÚ²ãÊÇ·Ç·¨µÄ.
b.ʹÓÃGOTO×Ó¾ä´ÓÒ»¸öIF×Ó¾äÌøµ½ÁíÒ»¸ö×Ó¾äÖÐÒ²ÊÇ·Ç·¨µÄ.
begin
......
È·¶¨¸ø¶¨µÄ×Ö·û´®ÊÇ·ñÓëÖ¸¶¨µÄģʽƥÅ䡣ģʽ¿ÉÒÔ°üº¬³£¹æ×Ö·ûºÍͨÅä·û×Ö·û¡£Ä£Ê½Æ¥Åä¹ý³ÌÖУ¬³£¹æ×Ö·û±ØÐëÓë×Ö·û´®ÖÐÖ¸¶¨µÄ×Ö·ûÍêÈ«Æ¥Å䡣Ȼ¶ø£¬¿É ʹÓÃ×Ö·û´®µÄÈÎÒâƬ¶ÎÆ¥ÅäͨÅä·û¡£ÓëʹÓà = ºÍ != ×Ö·û´®±È½ÏÔËËã·ûÏà±È£¬Ê¹ÓÃͨÅä·û¿Éʹ LIKE ÔËËã·û¸ü¼ÓÁé»î¡£Èç¹ûÈκβÎÊý¶¼²»ÊôÓÚ×Ö·û´®Êý¾ÝÀàÐÍ£¬Microsoft SQL Server ......
ת×Ô£º°Ù¶È°Ù¿Æ
Ëùν¶Ë¿Ú£¬¾ÍÊÇÏ൱ÓÚ»úÆ÷ÓëÍâ½ç½Ó´¥µÄ´°¿Ú¡£¶Ë¿ÚÆäʵÊÇÈí¼þµÄ´°¿Ú£¬¾ÍÊÇ˵һ¸öÈí¼þÈç¹ûÒªºÍÍâ½çÁªÏµ£¬¾Í±ØÐë´ò¿ªÒ»¸ö¶Ë¿Ú£»1434¶Ë¿ÚÊÇ΢ÈíSQL Serverδ¹«¿ªµÄ¼àÌý¶Ë¿Ú¡£ÄãҪʹÓÃSQL£¬¾Í±ØÈ»´ò¿ª1433ºÍ1434¶Ë¿Ú¡£
ĬÈÏÇé¿öÏ£¬SQL ServerʹÓÃ1433¶Ë¿Ú¼àÌý£¬ºÜ¶àÈ˶¼ËµSQL ServerÅäÖõÄʱºòÒª°ÑÕâ¸ö¶Ë¿Ú¸Ä± ......