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

SQL SERVERÖÐһЩÌرðµØ·½µÄÌرð½â·¨

--1.¹ØÓÚwhereɸѡÆ÷ÖгöÏÖÖ¸¶¨ÐÇÆÚ¼¸µÄÇó½â
SQL code
--»·¾³
create table test_1
(
id int,
value varchar(10),
t_time datetime
)
insert test_1
select 1,'a','2009-04-19' union
select 2,'b','2009-04-20' union
select 3,'c','2009-04-21' union
select 4,'d','2009-04-22' union
select 5,'e','2009-04-23' union
select 6,'f','2009-04-24' union
select 7,'g','2009-04-25'
go
ÎÒÃÇÒ»°ãͨ¹ý datepart(weekday )½øÐÐÇó½â£¬±ÈÈçÇó½âÐÇÆÚ2µÄ¼Ç¼
select * from test_1
where DATEPART(WEEKDAY,t_time+@@DATEFIRST-1)=2
/*
id value t_time
----------- ---------- -----------------------
3 c 2009-04-21 00:00:00.000
*/
ÕâÀïÉæ¼°µ½ @@datefirst Õâ¸öϵͳ±äÁ¿£¬Ò»°ãÎÒÃÇÓÃÀ´µ÷½Ú²»Í¬µØ·½µÄÈÕÆÚÏ°¹ß¡£
Èç¹ûÄã¾õµÃ¹ØÓÚÕâ¸ö±äÁ¿ºÜÄÑÒ²ÀÁµÃÈ¥ÒÀÀµËüµ÷½Ú£¬ÕâÀﻹÓÐÒ»ÖÖ·½·¨
Äã¿ÉÒÔʹÓÃÒ»¸ö²ÎÕÕÈÕÆÚ,ͨ¹ýÏàͬÐÇÆÚÊý³É7µÄ±¶ÊýµÄÔ­Àí½øÐвéѯ
select * from test_1
where DATEDIFF(DAY,'1900-01-02',t_time)%7=0
/*
id value t_time
----------- ---------- -----------------------
3 c 2009-04-21 00:00:00.000
*/
--2.¹ØÓÚÔÚwhereɸѡÆ÷ÖÐÖ¸¶¨´óСд²éÕÒµÄË÷ÒýÒýÓÃÎÊÌâ
SQL code
--»·¾³
--drop table test_2
create table test_2
(
id int identity(1,1),
value varchar(10)
)
insert test_2 select
'abc' union all select
'Abc' union all select
'ABC' union all select
'aBc'
go
create clustered index in_value on test_2(value)
--ÎÒÏÈÒª²éÕÒ ÖµÎª'ABC'µÄ¼Ç¼ ÒªÇø·Ö´óСдµÄ
select * from test_2
where value COLLATE CHINESE_PRC_CS_AS ='ABC'
°´CTRL+L¿´Ö´Ðмƻ® ·¢ÏÖʱ¾Û¼¯Ë÷ÒýɨÃè Õâ¾Í˵Ã÷Ëü²»ÊÇSARG£¬²»¿¼ÂÇʹÓÃË÷Òý
½â¾ö·½·¨:
select * from test_2
where value COLLATE CHINESE_PRC_CS_AS ='ABC'
and value='ABC'
go
--3.×Ô¶¯È«¾ÖÁÙʱ±í
SQL code ÔÚijЩÇé¿öÏ£¬Äã¿ÉÄÜÐèÒª¿ç»á»°µÄά»¤Ò»Ð©¹²ÏíÖµ£¬ÕâÀï¿ÉÒÔͨ¹ýһЩÊÖ¶Î×Ô¶¯½¨Á¢ÕâÑùÒ»¸öÈ«¾ÖÁÙʱ±í¹»ÄãʹÓÃ
¾ßÌå·½·¨¾ÍÊÇÔÚmasterÊý¾Ý¿âÖн¨Á¢Ò»¸öÒÔsp_¿ªÍ·µÄÌØÊâ´æ´¢¹ý³Ì£¬²¢ÇÒʹÓÃ'startup'±êÖ¾´Ë´æ´¢¹ý³Ì£¬ÕâÑùÿ´ÎÖØÆôÊý¾Ý¿âºó¶¼»á×Ô¶¯ÔËÐд˴洢¹ý³Ì£¬
ͨ¹ýÔÚ´æ´¢¹ý³ÌÖн¨Á¢È«¾ÖÁÙʱ±í£¬¾Í´ïµ½


Ïà¹ØÎĵµ£º

ÀûÓÃSQLÒƶ¯Ó²ÅÌÎļþ

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_movefile]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_movefile]
GO
/*--Òƶ¯·þÎñÆ÷ÉϵÄÎļþ
 ²»½èÖú xp_cmdshell ,ÒòΪÕâ¸öÔÚ´ó¶àÊýʱºò¶¼±»½ûÓÃÁË
--×Þ½¨ 2004.08(ÒýÓÃÇë±£Áô´ËÐÅÏ¢)--*/
/*--µ÷ÓÃʾÀý ......

½â¾öSQL ServerÀïsp_helptextÊä³ö¸ñʽ´íÐÐÎÊÌâ

use Master 
go 
if object_id('SP_SQL') is not null 
  drop proc SP_SQL 
go 
create proc [dbo].[SP_SQL](@ObjectName sysname) 
as 
set nocount on ; 
declare @Print varchar(max) 
if exists(select 1 from syscomments  where ID=objec ......

sql isnullº¯ÊýµÄʹÓÃ


sql isnullº¯ÊýµÄʹÓÃ
ISNULL
ʹÓÃÖ¸¶¨µÄÌæ»»ÖµÌæ»» NULL¡£
Óï·¨
ISNULL ( check_expression , replacement_value )
²ÎÊý
check_expression
½«±»¼ì²éÊÇ·ñΪ NULLµÄ±í´ïʽ¡£check_expression ¿ÉÒÔÊÇÈκÎÀàÐ͵ġ£
replacement_value
ÔÚ check_expression Ϊ NULLʱ½«·µ»ØµÄ±í´ïʽ¡£replacement_value ±ØÐëÓë chec ......

oracle sqlÓï¾äÓÅ»¯»ù´¡

¾¡Á¿ÉÙÓÃIN²Ù×÷·û£¬»ù±¾ÉÏËùÓеÄIN²Ù×÷·û¶¼¿ÉÒÔÓÃEXISTS´úÌæ¡£
²»ÓÃNOT IN²Ù×÷·û£¬¿ÉÒÔÓÃNOT EXISTS»òÕßÍâÁ¬½Ó+Ìæ´ú¡£
OracleÔÚÖ´ÐÐIN×Ó²éѯʱ£¬Ê×ÏÈÖ´ÐÐ×Ó²éѯ£¬½«²éѯ½á¹û·ÅÈëÁÙʱ±íÔÙÖ´ÐÐÖ÷²éѯ¡£¶øEXISTÔòÊÇÊ×Ïȼì²éÖ÷²éѯ£¬È»ºóÔËÐÐ×Ó²éѯֱµ½ÕÒµ½µÚÒ»¸öÆ¥ÅäÏî¡£NOT EXISTS±ÈNOT INЧÂÊÉԸߡ£µ«¾ßÌåÔÚÑ¡ÔñIN»òEXIST² ......

ORACLE SQLÓï¾äÓÅ»¯


1£© Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
ORACLEµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£Èç¹ûÓÐ3¸öÒÔÉϵıíÁ¬½Ó²éѯ, ÄǾÍÐèҪѡÔñ½»²æ±í(intersection ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ