资源描述:
《sql server 2008 示例数据库教程sql语句》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、--T-SQL字符串函数selectname,LEFT(name,12)asbiketype,SUBSTRING(name,9,4)asmodel,RIGHT(name,2)assize,RTRIM(style)asstylefromProduction.ProductwhereProductNumberlike'bk-t%';selectREPLACE(name,'mountain','Mtn')asReplaceName,STUFF(name,11,2,'x01')asStuffName,REVERSE(productnumber)a
2、sReverseNum,STUFF(productnumber,1,2,REPLICATE(0,3))asReplicateNum,productnumber+SPACE(4)+LOWER(productline)asProductLinefromProduction.ProductwhereProductID='771';selectname+CHAR(9)+str(makeflag)asProduct,ASCII(makeflag)asasciiMakeFlag,RTRIM(style)asstyle,UNICODE(rtrim(st
3、yle))asunicodeStylefromProduction.ProductwhereProductID='771';selectLEN(Description)asLenghthDescription,CHARINDEX('tech',description)asCharIndexDescription,PATINDEX('%bike%',description)asPatindexDescriptionfromProduction.ProductDescriptionwhereProductDescriptionID='321'
4、;select*fromProduction.ProductDescriptionwhereProductDescriptionID='321';declare@Name1varchar(30)set@Name1=(selectlastnamefromPerson.ContactwhereContactID='1829')declare@Name2varchar(30)set@Name2=(selectlastnamefromPerson.ContactwhereContactID='2580')select@Name1asName1,@
5、Name2asName2,Soundex(@Name1)assoundexname1,soundex(@Name2)assoundexname2,difference(@Name1,@Name2)assoundexdiff--T-SQL数学函数selectTerritoryID,AVG(SubTotal)asavgsales,SUM(subtotal)assumsales,MAX(subtotal)asmaxsales,MIN(subtotal)asminsalesfromSales.SalesOrderHeadergroupbyTerr
6、itoryIDorderbyTerritoryIDselectmin(name)asfirstproduct,MAX(name)aslastproductfromProduction.ProductselectCOUNT(*)asproductcount,COUNT(productmodelid)asmodelcount,COUNT(distinctProductModelID)asdistinctcountfromProduction.ProductselectColor,AVG(listprice)asavgprice,COUNT(*
7、)astotalAmount,GROUPING(color)asaggGroupfromProduction.ProductgroupbyColorwithrollupselectCHECKSUM_agg(CAST(Quantityasint))aschecksum_agg,CHECKSUM_agg(distinctCAST(quantityasint))aschecksumdistinctfromProduction.ProductInventoryselect*fromProduction.ProductInventorydeclar
8、e@agenlefloatset@agenle=3.1415926declare@sinefloatset@sine=SIN(@agenle)select@sineassine,degrees