Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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º¯Êý£¬ËùÒÔ´Ëʱ¿Ï¶¨²»»á³ö´í£¬ÆäËûµÄÖ±½Ó·µ»ØÒ»¸ö¿


Ïà¹ØÎĵµ£º

SQL2005ºÍ(Excel |access)Ö®¼äµÄÊý¾Ýµ¼Èëµ¼³ö


Sql´úÂë
--²ÉÓÃSQLÓï¾äʵÏÖsql2005ºÍExcel Êý¾ÝÖ®¼äµÄÊý¾Ýµ¼Èëµ¼³ö£¬ÔÚÍøÉÏÕÒÀ´Ò»--Ï£¬ÊµÏÖ·½·¨ÊÇÕâÑùµÄ£º    
  
  
--Excel---->SQL2005  µ¼È룺    
  
  
select * into useinfo from O ......

SQL SERVER ÓëACCESS¡¢EXCELµÄÊý¾Ýת»»

ÊìϤSQL SERVER 2000µÄÊý¾Ý¿â¹ÜÀíÔ±¶¼ÖªµÀ£¬ÆäDTS¿ÉÒÔ½øÐÐÊý¾ÝµÄµ¼Èëµ¼³ö£¬Æäʵ£¬ÎÒÃÇÒ²¿ÉÒÔʹÓÃTransact-SQLÓï¾ä½øÐе¼Èëµ¼³ö²Ù×÷¡£ÔÚTransact-SQLÓï¾äÖУ¬ÎÒÃÇÖ÷ҪʹÓÃOpenDataSourceº¯Êý¡¢OPENROWSET º¯Êý£¬¹ØÓÚº¯ÊýµÄÏêϸ˵Ã÷£¬Çë²Î¿¼SQLÁª»ú°ïÖú¡£ÀûÓÃÏÂÊö·½·¨£¬¿ÉÒÔÊ®·ÖÈÝÒ×µØʵÏÖSQL SERVER¡¢ACCESS¡¢EXCELÊý¾Ýת»»£ ......

SQL ÐÐÁл¥×ª

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

¾ÛºÏº¯Êý (Entity SQL)

SQL Server .NET Framework Êý¾ÝÌṩ³ÌÐò (SqlClient) Ìṩ¾ÛºÏº¯Êý¡£¾ÛºÏº¯Êý¶ÔÒ»×éÊäÈëÖµÖ´ÐмÆËã²¢·µ»ØÒ»¸öÖµ¡£ÕâЩº¯ÊýλÓÚ SqlServer ÃüÃû¿Õ¼äÖУ¬¸ÃÃüÃû¿Õ¼äÔÚÄúʹÓà SqlClient ʱ¿ÉÓá£Ìṩ³ÌÐòµÄÃüÃû¿Õ¼äÊôÐÔʹʵÌå¿ò¼Ü¿ÉÒÔÈ·¶¨´ËÌṩ³ÌÐò¶ÔÌض¨¹¹Ô죨ÈçÀàÐͺͺ¯Êý£©Ê¹ÓÃÄĸöǰ׺¡£
ϱíÏÔʾ SqlClient ¾ÛºÏº¯Êý¡£ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ