资源描述:
《证券法律冲突研究法学理论论文》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、sql语句中日期时间格式化查询(DateandtimeformattedqueryinSQLstatement)Editdelete
2、datetimeformatSQLstatementinthequerySnowtigerpublished:2007-12-1413:48Todayinsearchofmembermanagementsystem,Ifoundthatthesearchtimeisnotveryscientific,efficiencyisnottoohigh.Especiallywhensearchingthesametimespecifiedinthedata
3、base,Ihavesuchatimeformat"2007-5-2214:32:12"whenweareinthequerywhether2007-5-22anditsresultisequal.Notequal.Weallliketofindotherwaystosolvethisproblem.ButIfoundthatourmethodsweren'tverygood,becausewesometimeshadSQLSeverYoudon'tknowenoughaboutthesentencefeatures.SoIcheckedtheSQLServerhelp,andf
4、inallyfoundagoodthing,youcansolvethisproblemTheCONVERTfunctioncansolvethisproblembyformattingthetimelike2007-5-2214:32:12inthequeryorwhereclause:2007-5-22;Asfollows:IwillchecktheregistrationtimeoftheuserUserRegisterTimeSelect*from[user]whereUserActive=0andreplace(CONVERT(char(10),UserRegister
5、Time,111),='2007-05-22'orderby','-')UserRegisterTimedescInthiskeysentenceReplace(CONVERT(char(10),UserRegisterTime,111),'/','-');WhydoIwantreplacetochangethe"/"symbolinconvertto"-"?Becausetheformattingtimeofconverthereis:2007/05/22Onemorethingtonote:theformattingtimeofconvertisintheformof0bef
6、ore,suchas2007-1-112:12:31:2007-01-01,sobeforeyouquery,it'snecessarytoadd0tothenumberofmonthsanddayslessthan10(excluding10)inyourdate,Forexample:1shouldbe01Thespecificusageofthisnumberisasfollows:TransformationfunctionWhenMicrosoft?SQLServer?2000doesnotautomaticallyperformexpressiontransforma
7、tionsofdifferentdatatypes,conversionfunctionsCASTandCONVERTcanbeusedtoconvertthem.Thesetransformationfunctionscanalsobeusedtoobtainvariousspecialdataformats.Thesetwotransformationfunctionscanbeusedtoselectlists,Whereclauses,andanywherethatallowsexpressionstobeused.IfyouwanttheTransact-SQLprog
8、ramcodetocomplywiththeSQL-92standard,useCASTinsteadofusingCONVERT.IfyouwanttousethestylefunctioninCONVERT,useCONVERTinsteadofCAST.WhenusingCASTorCONVERT,twomessagesareneeded:Expressionstobeconverted(forexample,salesreportsrequiresalesdatatobe