×Ô¶¨Òå¶à²ÎÊýSql¾ÛºÏº¯Êý
Creating a CLR user define aggregate (part 2). Use multiple columns in the aggregation function
In part 1 we created a nice user defined aggregate. Now we are going to make it more sophisticated and let its value depend on two parameters ShipCountry and ShipShipCity. You might try having two parameters in Accumulate function of the aggregate but you will get an error
The Accumulate method in user defined aggregate "Bonus" must have exactly one parameter.
We are definitely looking into adding “multi-column aggregates” feature in the future versions of SQL Server. For now you can use a workaround. The idea is to create a worker UDT that contain all the fields required for the aggregation. So if you want to take Orders.ShipCountry and Orders.ShipCity into account the UDT should have two corresponding fields. You also need to create a user defined function that takes a number of parameters and returns an instance of the worker UDT. And finally you create an aggregate that takes the worker UDT as a parameter in its aggregation function.
Let’s say XYZ wants to consider German sales that has been shipped to Berlin as regular sales. To take ShipCity this into account you first need to create a UDT. I won’t implement several methods to keep the sample short.
[Serializable]
[Microsoft.SqlServer.Server.SqlUserDefinedType(Format.UserDefined, MaxByteSize=8000)]
public struct OrderData : INullable, IBinarySerialize
{
public override string ToString()
{
throw new Exception("The method or operation is not implemented.");
}
public bool IsNull
{
get
{
return false;
}
}
&n
Ïà¹ØÎĵµ£º
for i=0,i++,i<@num
select dateadd(DAY,GETDATE(),I)
ÇëÎÊÉÏÃæµÄÓï¾äÔõô¸Äд²ÅÕýÈ·£¿£¿£¿
Transact-SQL ²Î¿¼
WHILE
ÉèÖÃÖØ¸´Ö´ÐÐ SQL Óï¾ä»òÓï¾ä¿éµÄÌõ¼þ¡£Ö»ÒªÖ¸¶¨µÄÌõ¼þÎªÕæ£¬¾ÍÖØ¸´Ö´ÐÐÓï¾ä¡£¿ÉÒÔʹÓà BREAK ºÍ CONTINUE ¹Ø¼ü×ÖÔÚÑ»·ÄÚ²¿¿ØÖÆ WHILE Ñ»·ÖÐÓï¾äµÄÖ´ÐС£
Óï·¨
WHILE Boolean_expression
{ s ......
exec sp_spaceused [[@objname=]'objname'][,[@updateusage=]'updateusage']
¼ì²éÊý¾Ý¿â¿Õ¼ä´óС
dbcc showfilestats
ͳ¼ÆÊý¾ÝÎļþµÄʹÓÃÇé¿ö
dbcc showcontig
¼ì²éÊý¾Ý¿â¿Ø¼þ·ÖÅäÇé¿ö
dbcc sqlperf(logspace)
²é¿´ÈÕÖ¾ÎļþµÄʹÓÃÇé¿ö ......
Õª×Ô£ºÒÁÒÇÇïË®
SQL Server Management Studio (SSMS) µÄ“Á¬½Óµ½·þÎñÆ÷”¶Ô»°¿ò»á¼Ç¼Óû§ËùÓзÃÎʹýµÄ·þÎñÆ÷Ãû³Æ£¬Õâ¸ö¹¦ÄܶÔÓÚ¾³£Á¬½Ó¶à¸öÊý¾Ý¿âµÄÈËÀ´ËµÈ·ÊµÍ¦·½±ãµÄ¡£
²»¹ýʹÓÃÁËÒ»¶Îʱ¼äÖ®ºó£¬Õâ¸öÁбí»á±äµÃºÜ³¤¡£ÀïÃæ»¹Óкܶà·þÎñÆ÷Ãû³Æ¶¼ÒѾʧЧÁË£¬ºÜÏë°ÑÕâ¸öÁбíÇå¿ÕÁË¡£µ«ÊǺÜÓôÃÆÔÚSSMSµÄ½çÃæÕÒ ......
ORACLEÓëSQL SERVERÓï·¨Çø±ð
Ò»¡¢Êý¾ÝÀàÐÍ
ORACLEÓëSQL SERVERÔÚÊý¾ÝÀàÐ͵ĶԱÈÈçÏ£º
SQL SERVER
ORACLE
Êý×ÖÀàÐÍ
DECIMAL[(P[, S])]
NUMBER[(P[, S])]
NUMERIC[(P[, S])]
NUMBER[(P[, S])]
FLOAT[(N)]
NUMBER[(N)]
INT
NUMBER
SMALLINT
NUMBER
TINYINT
NUMBER
MONEY
NUMBER[19,4]
SM ......
SQLµÄÓÅ»¯Ó¦¸Ã´Ó5¸ö·½Ãæ½øÐе÷Õû£º
1.È¥µô²»±ØÒªµÄ´óÐͱíµÄÈ«±íɨÃè
2.»º´æÐ¡ÐͱíµÄÈ«±íɨÃè
3.¼ìÑéÓÅ»¯Ë÷ÒýµÄʹÓÃ
4.¼ìÑéÓÅ»¯µÄÁ¬½Ó¼¼Êõ
5.¾¡¿ÉÄܼõÉÙÖ´Ðмƻ®µÄCost
SQLÓï¾ä£º
ÊǶÔÊý¾Ý¿â(Êý¾Ý)½øÐвÙ×÷µÄΩһ;¾¶£»
ÏûºÄÁË70%~90%µÄÊý¾Ý¿â×ÊÔ´£»¶ÀÁ¢ÓÚ³ÌÐòÉè¼ÆÂß¼£¬Ïà¶ÔÓÚ¶Ô³ÌÐòÔ´´úÂëµÄÓÅ»¯£¬¶ÔSQLÓï¾äµÄÓÅ»¯Ô ......