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

SQLÓÃDataDiff²éѯµÄ¹ÖÏÖÏó¶øÒý·¢µÄ˼¿¼¡£¡£

½ñÌìÓÖ¿´µ½Ð¼ÓƵÄͬÊ·¢¹ýÀ´µÄÒ»¶ÎSQLÓï¾ä£¬»¹ÊÇÀÏÎÊÌ⣬ʱ¼ä¶Ô±ÈÖ±½ÓÓôóÓÚСÓںš£Ì¾ÁËÉùÆøºó£¬ÊÖ¶¯¸ø¸Ä³ÉdatediffÁË£¬¿ÉÊÇÒ»ÔËÐгö´í£¬´íÎóÌáʾÈçÏ£º
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting datetime from character string.
ΪÁË˵Ã÷·½±ã£¬ÕâÀï¾Í¼ò»¯Ò»¸öÀý×ÓºÃÁË¡£
create table a
(
   id int not null,
   val   varchar(20)
)
insert into a values (1, '2009-05-02')
insert into a values (2, 'abc')
insert into a values (3, '2009-12-10')
ÎÒµÄÓï¾äÊÇÕâÑùµÄ:
select * from a where id in (1,3) and datediff(day, convert(datetime,val),getdate()) < 0
°´³£Àí£¬ÎÒÏÈÕÒµ½id= 1»ò3µÄ¼Ç¼£¬È»ºóÔÙ¸ú½ñÌì±È½Ï£¬Ó¦¸Ã»á·µ»Øid=1µÄ¼Ç¼°¡¡£¿ÉÊǾÓÈ»³öÏÖÈçÏ´íÎó£º
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting datetime from character string.
¿ÉÊǵ±ÎÒÖ´ÐУº
select datediff(day, convert(datetime,val),getdate()) from a where id in (1,3)
ÕâʱºòÓÖÊÇÄܹ»Ö´Ðеġ£ Õâ¾ÍÊÇ˵ÔÚ½øÐÐ1»ò3µÄÅжÏÇ°£¬ÒѾ­¶Ôid=2ÕâÌõ¼Ç¼ִÐÐÁËconvert£¬ËùÒÔ³ö´íÁË¡£
Óɴ˿ɼû£¬Óï¾ä²¢²»ÊÇÎÒÃÇÏëÏóµÄÓÉÉϵ½ÏÂÖ´Ðеģ¬ÄѵÀÊÇÓÉÏÂÏòÉÏÖ´Ðеģ¿»»³ÉÈçÏÂÓï¾ä:
select * from a where datediff(day, val,getdate()) < 0 and id in (1,3)
´íÎóÒÀ¾É¡£
ÔÎÁË£¬²»ÊÇÓÉÉϵ½Ï£¬Ò²²»ÊÇÓÉϵ½ÉÏ£¬ÄѵÀÕâ¸ö˳Ðò²»Êǹ̶¨µÄ£¿ ×Ðϸ·ÖÎöһϣ¬ÉÏÃæÒ»¸ö¿ÉÒÔÖ´ÐеÄÓï¾ä¿ÉÒÔ·¢ÏÖ,
ÓÉÓÚconvertº¯ÊýÊÇÔÚËù²éѯ³öÀ´µÄ½á¹û¼¯ÉÏÔÙ½øÐеÄת»»£¬¶øÇÒid = 1»ò3µÄ¼Ç¼ÖеÄvalÁж¼ÊÇ¿ÉÒÔת»»ÎªÊ±¼äÀàÐ͵ģ¬ËùÒÔ
ûÓÐÈκδíÎó¡£ ÆäËûÁ½¸öÔËÐÐÓдíÎóµÄÓï¾äÖУ¬ÔÚÖ´ÐеÄʱºò¶¼ÊÇÔÚ±íÖÐËùÓмǼµÄ»ù´¡ÉÏ£¬Ïȵ÷ÓÃconvertÕâ¸öÌõ¼þµÄ£¬ËùÒÔ
µ±Óöµ½id=2ÕâÌõ¼Ç¼ʱ£¬¾Í»á³ö´í¡£¼ÈÈ»SQL server²»ÊÇ°´ÕÕÎÒÃÇÏëÒªµÄ˳ÐòÈ¥Ö´ÐУ¬ÄÇôÎÒÃÇÄܲ»ÄÜÇ¿ÖÆÈÃËüÈ¥°´ÎÒÃǵÄËùÒªÇóµÄ
˳ÐòÈ¥Ö´ÐÐÄØ£¿
ÓÚÊǺõ£¬ºÃÓõÄcase when ¾ÍÅÉÉÏÓó¡ÁË¡£ÎÒ°ÑÉÏÃæµÄÓï¾ä¸ÄΪÈçÏ£º
select * from a where (case when id in (1,3) then datediff(day, convert(datetime,val),getdate()) else 1 end) < 0
ÈçÉÏÃæËùʾ£¬ÔÚwhere Ìõ¼þÖУ¬Ê×ÏÈÅÐ¶Ï µ± id in (1,3) £¬Ôò½øÐÐdatediffºÍconvertº¯ÊýµÄµôÓ㬴ËʱֻÓÐid = 1»ò3µÄ¼Ç¼²Å»áµ÷ÓÃconvertº¯Êý£¬ËùÒÔ´Ëʱ¿Ï¶¨²»»á³ö´í£¬ÆäËûµÄÖ±½Ó·µ»ØÒ»¸ö¿


Ïà¹ØÎĵµ£º

AccessºÍSQL2000ÖÐÓï¾äµÄÇø±ð

1 £¬¶ÔÓÚÈÕÆÚ×Ö¶Î×Ö¶Î
access±íʾΪ£º#1981-28-12#
SQLSERVER2000±íʾΪ£º''1981-02-12''
2,SQLÓï¾äÇø±ð£¬select ,update ÔÚ¶Ôµ¥±í²Ù×÷ʱ¶¼²î²»¶à£¬
µ«¶à±í²Ù×÷ʱupdateÓï¾äµÄÇø±ðACCESSÓëSQLSERVERÖеÄUpdateÓï¾ä¶Ô±È:
SQLSERVERÖиüжà±íµÄUpdateÓï¾ä:
Update Tab1
SET a.Name = b.Name
from Tab1 a,Tab2 b
Whe ......

[ÊÕ£] ÓÃsqlite Ö´Ðбê×¼ sql Óï·¨

http://www.umgr.com/blog/PostView.aspx?bpId=36294
 1. Ö´ÐÐsqlÓï¾ä
int sqlite3_exec(sqlite3*£¬ const char *sql£¬ sqlite3_callbacksql Óï·¨
£¬ void *£¬  char **errmsg );
Õâ¾ÍÊÇÖ´ÐÐÒ»Ìõ sql Óï¾äµÄº¯Êý¡£
µÚ1¸ö²ÎÊý²»ÔÙ˵ÁË£¬ÊÇÇ°Ãæopenº¯ÊýµÃµ½µÄÖ¸Õ롣˵ÁËÊǹؼüÊý¾Ý½á¹¹¡£
µÚ2¸ö²ÎÊýconst char ......

SQL ÐÐÁл¥×ª

--ÐÐÁл¥×ª
/******************************************************************************************************************************************************
ÒÔѧÉú³É¼¨ÎªÀý×Ó£¬±È½ÏÐÎÏóÒ׶®
ÕûÀíÈË£ºÖйú·ç(Roy)
ÈÕÆÚ:2008.06.06
***************************************************************** ......

PL/SQL±í


/*
PL/SQL±í---table()º¯ÊýÓ÷¨£º
ÀûÓÃtable()º¯Êý£¬ÎÒÃÇ¿ÉÒÔ½«PL/SQL·µ»ØµÄ½á¹û¼¯´úÌætable¡£
oracleÄÚ´æ±íÔÚ²éѯºÍ±¨±íµÄʱºòÓõıȽ϶࣬ËüµÄËÙ¶ÈÏà¶ÔÎïÀí±íÒª¿ì¼¸Ê®±¶¡£
simple example£º
1¡¢table()½áºÏÊý×飺
*/
create or replace type t_test as object(
id integer,
rq date,
mc varchar2(60)
);
cr ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ