Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

sqlÓï¾äѧϰ±Ê¼Ç(6) ³£ÓÃ×Ö·û´®²Ù×÷º¯Êý

ÕâЩº¯ÊýÔÚϵͳº¯Êý¿ÉÒÔÕÒµ½¡£ÏÂÃæÊÇÎÒÁ·Ï°Ê±Ð´µÄ´úÂ룬°üº¬Á˳£ÓõÄ×Ö·û´®²Ù×÷º¯Êý
/*********************************
³£ÓÃ×Ö·û´®º¯Êý:sqlÖÐûÓÐÊý×éÕâһ˵
*********************************/
--int charindex('ÒªÕÒµÄ×Ö·û´®','Ô´×Ö·û´®',¿ªÊ¼Î»ÖÃ)£¬»ñÈ¡×Ö·û´®ÖÐÖ¸¶¨×Ö·û´®µÄλÖÃ
declare @str varchar(50)
set @str='½­ËÕ|ºþ±±|ºþÄÏ|ɽ¶«|ɽÎ÷|ºÓÄÏ|ºÓ±±'
print 'ԭʼÊäÈëÊý¾Ý:'+@str
print Charindex('ºþ',@str,1)--Êä³öΪ4£¨×Ö·û´®²Ù×÷ÖеÄÆðʼλÖÃÊÇ1¶ø²»ÊÇ0£©
--Çø±ðÓÚcharindex£¬ÊÇÒ»ÖÖģʽƥÅä
--²Î¿¼×ÊÁÏhttp://msdn.microsoft.com/zh-cn/library/ms190184.aspx
declare @str varchar(50)
set @str='½­ËÕ|ºþ±±|ºþÄÏ|ɽ¶«|ɽÎ÷|ºÓÄÏ|ºÓ±±'
print 'ԭʼÊäÈëÊý¾Ý:'+@str
print patindex('%ºþ%',@str)--Êä³ö4
--string substring('Ô´×Ö·û´®'£¬ÆðʼλÖ㬳¤¶È)£¬´ÓÔ´×Ö·û´®ÖÐÖ¸¶¨Î»ÖÿªÊ¼»ñÈ¡Ö¸¶¨³¤¶ÈµÄ×Ö·û´®
declare @str varchar(50)
set @str='½­ËÕ|ºþ±±|ºþÄÏ|ɽ¶«|ɽÎ÷|ºÓÄÏ|ºÓ±±'
print 'ԭʼÊäÈëÊý¾Ý:'+@str
print substring(@str,1,2)--´òÓ¡³ö‘½­ËÕ’
--string replace(‘Ô´×Ö·û´®’'Òª±»Ìæ»»µÄ×Ö·û´®'£¬‘ÒªÌæ»»µÄ×Ö·û´®’)
declare @str varchar(50)
set @str='½­ËÕ|ºþ±±|ºþÄÏ|ɽ¶«|ɽÎ÷|ºÓÄÏ|ºÓ±±'
print 'ԭʼÊäÈëÊý¾Ý:'+@str
print replace(@str,'|','+')--½«Ô´×Ö·û´®ÖеÄ-»»³ÉÁË+
--int len('Ô´×Ö·û´®')£ºÇóÖ¸¶¨×Ö·û´®µÄ³¤¶È
declare @str varchar(50)
set @str='½­ËÕ|ºþ±±|ºþÄÏ|ɽ¶«|ɽÎ÷|ºÓÄÏ|ºÓ±±'
print '×Ö·û´®µÄ³¤¶ÈΪ£º'+convert(varchar(4),len(@str))--Êä³ö20
--string upper('Ô´×Ö·û´®')£º×ª»»³É´óд£¬string lower('Ô´×Ö·û´®')£º×ª»»³ÉСд
declare @str varchar(10)
set @str='Sql Server'
print upper(@str)--Êä³öΪSQL SERVER
print lower(@str)--Êä³öΪsql server
--string ltrim('Ô´×Ö·û´®')£º·µ»ØÈ¥µôÇ°µ¼¿Õ¸ñºóµÄ×Ö·û´®
declare @str varchar(10)
set @str='  Sql Server'
print ltrim(@str)--Êä³ö£ºSql Server
--string left('Ô´×Ö·û´®',Ö¸¶¨³¤¶È)£º´ÓÔ´×Ö·û´®ÖÐ×î×ó±ß·µ»ØÖ¸¶¨³¤¶ÈµÄ×Ö·û´®
--string right('Ô´×Ö·û´®',Ö¸¶¨³¤¶È)£º´ÓÔ´×Ö·û´®ÖÐ×îÓұ߷ű߷µ»ØÖ¸¶¨³¤¶ÈµÄ×Ö·û´®
declare @str varchar(50)
set @str='½­ËÕ|ºþ±±|ºþÄÏ|ɽ¶«|ɽÎ÷|ºÓÄÏ|ºÓ±±'
print left(@str,5)--Êä³ö:½­ËÕ|ºþ±±
print right(@str,5)--Êä³ö£ºº


Ïà¹ØÎĵµ£º

SqlÓï¾äѧϰ±Ê¼Ç(2) ´´½¨Êý¾Ý±í

use RetalDB--±íʾÔÚÊý¾Ý¿âRetalDBÖнøÐеIJÙ×÷
go
if exists (select * from sysobjects where name='tb_user')
 drop table tb_user
go
--´´½¨¿Í»§±ítb_user
create table tb_user
(
 user_id int primary key,--Ö¸¶¨ÎªÖ÷¼üʱ£¬´ËÁÐĬÈÏΪ·Ç¿Õ£¬Ö¸¶¨¹ý¶à¸öÏÞÖÆÌõ¼þʱ²»ÓÓ'”¸ô¿ª
 us ......

SqlÓï¾äѧϰ±Ê¼Ç(3) ²åÈëÊý¾Ý

ÕâÀïʹÓõÄÊý¾Ý¿âºÍÊý¾Ý±í·Ö±ðÀ´×ÔSqlÓï¾äѧϰ±Ê¼Ç£¨1£©——´´½¨Êý¾Ý¿âºÍSqlÓï¾äѧϰ±Ê¼Ç£¨2£©——´´½¨Êý¾Ý±í
use RetalDB
go
--²åÈëÊý¾Ýµ½±ítb_movie_type
insert tb_movie_type values(0,'ÆÕͨƬ','Regular')
insert tb_movie_type values(1,'ÐÂƬ','NewRelease')
insert tb_movie_type values ......

SQL Server 2005 Á¬½Ó×Ö·û´®

Ô­ÎÄת×Ô http://blog.csdn.net/jyh_jack/archive/2008/04/07/2257512.aspx
SQL Native Client ODBC Driver
 
±ê×¼°²È«Á¬½Ó
   
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
 
ÄúÊÇ·ñÔÚʹÓÃSQL Server 2005 Express£¿ Çë ......

ʹÓÃSQLÓï¾äÉú³ÉÊý¾Ý×Öµä

--sqlserver 2000
SELECT ±íÃû=case when a.colorder=1 then d.name else '' end,
--×Ö¶ÎÐòºÅ=a.colorder,
×Ö¶ÎÃû=a.name,
--
±êʶ=case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end,
/**/
Ö÷¼ü=case when exists(SELECT 1 from sysobjects where xtype='PK' and name
in ( ......

dz̸SQL½Ì³ÌÖ®Group byºÍHaving

ÔÚ½éÉÜGROUP BY ºÍ HAVING ×Ó¾äÇ°£¬ÎÒÃDZØÐèÏȽ²½²sqlÓïÑÔÖÐÒ»ÖÖÌØÊâµÄº¯Êý£º¾ÛºÏº¯Êý£¬ÀýÈçSUM, COUNT, MAX, AVGµÈ¡£ÕâЩº¯ÊýºÍÆäËüº¯ÊýµÄ¸ù±¾Çø±ð¾ÍÊÇËüÃÇÒ»°ã×÷ÓÃÔÚ¶àÌõ¼Ç¼ÉÏ¡£
      SELECT SUM(population) from bbc
¡¡¡¡ÕâÀïµÄSUM×÷ÓÃÔÚËùÓзµ»Ø¼Ç¼µÄpopulation×Ö¶ÎÉÏ£¬½á¹û¾ÍÊǸòéÑ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ