SQL½ØÈ¡×Ö·û´®
SQL½ØÈ¡×Ö·û´®
SUBSTRING
·µ»Ø×Ö·û¡¢binary¡¢text »ò image ±í´ïʽµÄÒ»²¿·Ö¡£ÓйؿÉÓë¸Ãº¯ÊýÒ»ÆðʹÓõÄÓÐЧMicrosoft SQL Server Êý¾ÝÀàÐ͵ĸü¶àÐÅÏ¢£¬Çë²Î¼ûÊý¾ÝÀàÐÍ¡£
Óï·¨
SUBSTRING ( expression , start , length )
²ÎÊý
expression
ÊÇ×Ö·û´®¡¢¶þ½øÖÆ×Ö·û´®¡¢text¡¢image¡¢Áлò°üº¬Áеıí´ïʽ¡£²»ÒªÊ¹Óðüº¬¾ÛºÏº¯ÊýµÄ±í´ïʽ¡£
start
ÊÇÒ»¸öÕûÊý£¬Ö¸¶¨×Ó´®µÄ¿ªÊ¼Î»Öá£
length
ÊÇÒ»¸öÕûÊý£¬Ö¸¶¨×Ó´®µÄ³¤¶È£¨Òª·µ»ØµÄ×Ö·ûÊý»ò×Ö½ÚÊý£©¡£
¾ÙÀý£º
select substring('600|900',1,CHARINDEX('|','600|900')-1)
select substring('600|900',CHARINDEX('|','600|900')+1,len('600|900'))
·Ö±ðÊä³ö£º600 900
'600|900'ÓñäÁ¿Ìæ»»
Ïà¹ØÎĵµ£º
1.ijҽԺ²¡·¿¼ÆËã»ú¹ÜÀíÖÐÐèÒªÈçÏÂÐÅÏ¢£º£¨15·Ö£©
¿ÆÊÒ£º¿ÆÃû£¬¿ÆµØÖ·£¬¿Æµç»°
²¡·¿£º²¡·¿ºÅ£¬ËùÊô¿ÆÊÒÃû
Ò½Éú£ºÐÕÃû£¬Ö°³Æ£¬ËùÊô¿ÆÊÒÃû£¬ÄêÁ䣬¹¤×÷Ö¤ºÅ
²¡ÈË£º²¡ÀúºÅ£¬ÐÕÃû£¬ÐÔ±ð£¬Õï¶Ï£¬Ö÷¹ÜÒ½Éú£¬²¡·¿ºÅ£¬ÈëסÈÕÆÚ
ÆäÖУ¬Ò»¸ö¿ÆÊÒÓжà¸ö²¡·¿¡¢¶à¸öÒ½Éú£¬Ò»¸ö²¡·¿Ö»ÄÜÊôÓÚÒ»¸ö¿ÆÊÒ£¬Ò»¸öÒ½ÉúÖ»ÊôÓÚÒ»¸ö¿ÆÊÒ£¬µ«¿É¸º ......
--Ê¡¼¶ Provincial
--³ÇÊÐ City
create table Provincial(pid int,Provincial varchar(50),primary key (pid))
insert into Provincial values(1,'±±¾©ÊÐ')
insert into Provincial values(2,'Ìì½òÊÐ')
insert into Provincial values(3,'ÉϺ£ÊÐ')
insert into Provincial values(4,'Ö ......
д³É´æ´¢¹ý³Ì£¬½¨Á¢×÷Òµ¶¨Ê±±¸·Ý~~~
--ÔÚsqlÖÐÓ³ÉäһϾͿÉÒÔÁË
exec master..xp_cmdshell 'net use z: \\yizhi\D$ "ÃÜÂë" /user:yizhi\administrator'
/*--˵Ã÷:
exec master..xp_cmdshell 'net use z: \\xz\c$ "ÃÜÂë" /user:xz\administrator'
z:ÊÇÓ³ÉäÍøÂç·¾¶¶ÔÓ¦±¾»úµÄÅÌ·û,ÓëÏÂÃæµÄ±¸·Ý¶ÔÓ¦
\\xz\c$ÊÇÒªÓ³ÉäµÄÍ ......
1.Á¬½ÓÊý¾Ý¿âÎļþ
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|TimeTracker.mdf;User Instance=true" />
SqlConnectionStringBuilderʵÀý»¯Ê±£¬ÒªÓõ½connectionString£¬È磺SqlConnectionStringBuild builder = new SqlC ......
Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseËÑË÷º¯Êý¡£
--¼òµ¥Caseº¯Êý
CASE sex
WHEN '1' THEN 'ÄÐ'
WHEN '2' THEN 'Å®'
ELSE 'ÆäËû' END
--CaseËÑË÷º¯Êý
CASE WHEN sex = '1' THEN 'ÄÐ'
WHEN sex = '2' THEN 'Å®'
ELSE 'ÆäËû' END
ÕâÁ½ÖÖ·½Ê½£¬¿ÉÒÔʵÏÖÏàͬµÄ¹¦ÄÜ¡£¼òµ¥Caseº¯ÊýµÄд·¨Ïà ......