sql serverÖÐ×Ö·û´®ÀàÐ͵ÄÈÕÆÚÈçºÎ±È½Ï´óС
Èç¹ûÔÚÊý¾Ý¿â£¨sql£©Öн«±£´æÈÕÆÚµÄ×ֶεÄÊý¾ÝÀàÐÍÉèÖÃΪvarchar£¬¶øÄãÓÖÐèÒª¶ÔÕâ¸öÈÕÆÚºÍÁíÍâÒ»¸öÈÕÆÚ½øÐбȽϣ¬ÄÇô¸ÃÔõô°ìÄØ£¿
1. µÚÒ»ÖÖ·½·¨ºÜÈÝÒ×Ïëµ½£¬¾ÍÊÇ´¿´âµØÀûÓÃ×Ö·û´®À´±È½Ï´óС£¬±ÈÈçÓÐÒ»¸ö×Ö¶ÎΪadddate,ÆäÊý¾ÝÀàÐÍΪvarchar£¬Òª±È½ÏÕâ¸öÈÕÆÚÊDz»ÊÇ´óÓÚij¸öÈÕÆÚ£¬±ÈÈç"2006-12-23",ÄÇô¿ÉÒÔÖ±½Óд£º
where adddate>'2006-12-23'£¬ÕâÖз½·¨ºÜÖ±¹Û£¬µ±È»Ò²ÐèÒªÔÚ¸ñʽÉÏÓÐËù¹æ·¶£¬±ÈÈ磬Èç¹ûÈÕÆÚÊÇ2006Äê3ÔÂ3ÈÕ£¬¾Í±ØÐ뽫ÈÕÆÚ±£´æΪ2006-03-03£¬·ñÔò±È½ÏµÄʱºòÈÝÒ׳ö´í¡£
2. µÚ¶þÖÖ·½·¨Ôò¿ÉÒÔÀûÓÃsqlÌṩµÄÈÕÆÚת»»º¯ÊýÁË¡£
CONVERT (<data_ type>[ length ]£¬ <expression> [£¬ style])
1£©data_typeΪSQL Serverϵͳ¶¨ÒåµÄÊý¾ÝÀàÐÍ£¬Óû§×Ô¶¨ÒåµÄÊý¾ÝÀàÐͲ»ÄÜÔÚ´ËʹÓá£
2£©lengthÓÃÓÚÖ¸¶¨Êý¾ÝµÄ³¤¶È£¬È±Ê¡ÖµÎª30¡£
3£©ÓÃCONVERT£¨£© º¯ÊýµÄstyle Ñ¡ÏîÄÜÒÔ²»Í¬µÄ¸ñʽÏÔʾÈÕÆÚºÍʱ¼ä¡£style Êǽ«DATATIME ºÍSMALLDATETIME Êý¾Ýת»»Îª×Ö·û´®Ê±ËùÑ¡ÓõÄÓÉSQL Server ϵͳÌṩµÄת»»Ñùʽ±àºÅ£¬²»Í¬µÄÑùʽ±àºÅÓв»Í¬µÄÊä³ö¸ñʽ¡£
Èç¹ûÓÃÕâÖÖ·½·¨À´ÅжÏijһ¸ö×ֶεĻ°£¬Ôò´æÈëµÄÈÕÆÚ×ֶεÄ×Ö·û´®¸ñʽֻҪÊÇÄÜÈÃsql serverÍê³É¶ÔÈÕÆÚµÄת»»¾Í¿ÉÒÔÁË£¬¶ø²»Ò»¶¨ÒªÏñµÚÒ»ÖÖ·½·¨ÖеÄÄÇÑùÑϸñ¡£
»¹ÊÇ˵adddate×ֶΣ¬±ÈÈçÒª±È½ÏËüÊÇ·ñ´óÓÚµ±Ç°µÄÈÕÆÚ£¬¾Í¿ÉÒÔÕâÑùд£º
where (CONVERT(varchar, adddate) >= CONVERT(varchar, GETDATE()))
Ïà¹ØÎĵµ£º
---·µ»Ø±í´ïʽÖÐÖ¸¶¨×Ö·ûµÄ¿ªÊ¼Î»ÖÃ
select charindex('c','abcdefg',1)
---Á½¸ö×Ö·ûµÄÖµÖ®²î
select difference('bet','bit')
---×Ö·û×î×ó²àÖ¸¶¨ÊýÄ¿
select left('abcdef',3)
---·µ»Ø×Ö·ûÊý
select len('abcdefg')
--ת»»ÎªÐ¡×Ö·û
select lower('ABCDEFG')
--È¥×ó¿Õ¸ñºó
select ltrim(' &nbs ......
MS SQL Server 2008 ÔÚ½¨Íê±íºó£¬Èç¹ûÒª²åÈëÈÎÒâÁУ¬ÔòÌáʾ£º
µ±Óû§ÔÚÔÚSQL Server 2008ÆóÒµ¹ÜÀíÆ÷Öиü¸Ä±í½á¹¹Ê±£¬±ØÐëÒªÏÈɾ³ýÔÀ´µÄ±í£¬È»ºóÖØд´½¨ÐÂ±í£¬²ÅÄÜÍê³É±íµÄ¸ü¸Ä£¬Èç¹ûÇ¿Ðиü¸Ä»á³öÏÖÒÔÏÂÌáʾ£º²»ÔÊÐí±£´æ¸ü¸Ä¡£ÄúËù×öµÄ¸ü¸ÄÒªÇóɾ³ý²¢ÖØд´½¨ÒÔÏÂ±í¡£Äú¶ÔÎÞ·¨ÖØд´½¨µÄ±ê½øÐÐÁ˸ü¸Ä»òÕßÆôÓÃÁË“× ......
ÐÐÁÐת»»
create table test(id int,name varchar(20),quarter int,profile int)
insert into test values(1,'a',1,1000)
insert into test values(1,'a',2,2000)
insert into test values(1,'a',3,4000)
insert into test values(1,'a',4,5000)
insert into test values(2,'b',1,3000)
insert into test values(2, ......
¡¡UNIONÖ¸ÁîµÄÄ¿µÄÊǽ«Á½¸öSQLÓï¾äµÄ½á¹ûºÏ²¢ÆðÀ´¡£´ÓÕâ¸ö½Ç¶ÈÀ´¿´£¬ ÎÒÃÇ»á²úÉúÕâÑùµÄ¸Ð¾õ£¬UNION¸úJOINËƺõÓÐЩÐíÀàËÆ£¬ÒòΪÕâÁ½¸öÖ¸Á¿ÉÒÔÓɶà¸ö±í¸ñÖÐߢȡ×ÊÁÏ¡£ UNIONµÄÒ»¸öÏÞÖÆÊÇÁ½¸ö SQL Óï¾äËù²úÉúµÄÀ¸Î»ÐèÒªÊÇͬÑùµÄ×ÊÁÏÖÖÀà¡£ÁíÍ⣬µ±ÎÒÃÇÓà UNIONÕâ¸öÖ¸Áîʱ£¬ÎÒÃÇÖ»»á¿´µ½²»Í¬µÄ×ÊÁÏÖµ (ÀàËÆ SELECT DISTINCT) ......
Óï·¨£º
isnull(check_expression,replacement_expression)
²ÎÊýcheck_expressionÓëreplacement_expressionÀàÐÍÐèÏàͬ
·µ»ØÖµ£º
Èôcheck_expressionΪnull£¬Ôò·µ»Øreplacement_expression
Èôcheck_expression²»Îªnull£¬Ôò·µ»Øcheck_expression ......