SlideShare a Scribd company logo
by Anney




 09/04/12   1
• COUNT(*)
    •8
• COUNT(Name)
    •6
• COUNT(DISTINCT Name)
    •4




09/04/12                 2
• COUNT(*)
    • returns the number of items in a group. This includes NULL
      values and duplicates.
• COUNT(ALL expression)
    • evaluates expression for each row in a group and returns the
      number of nonnull values.
• COUNT(DISTINCT expression)
    • evaluates expression for each row in a group and returns the
      number of unique, nonnull values.
• Tips
    • If return values greater than 2^31-1, COUNT produces an error.
    • COUNT_BIG()

09/04/12                                                               3
• REPLICATE
    • REPLICATE('0', 4 - LEN(3)) + CONVERT(varchar(4), 3)
• POWER
    • RIGHT(CONVERT(varchar(10), POWER(10, 4) + 3), 4)
    • 10000 + 3 => ‘10003’
    • Tips:
       • POWER ( float_expression , y )
       • 數值轉型兩次 (int -> float, float -> varchar)
• RIGHT
    • RIGHT('0000' + CONVERT(varchar(4), 3), 4)
    • ‘0000’ + ‘3’ => ‘00003’


09/04/12                                                    4
• sp_who2 procedure
    • 所有連線狀況 , 也可以看到連線是否有被卡住 (Blocked) 的狀況。




09/04/12                                  5
• sys.dm_exec_requests
• sys.dm_exec_sql_text(sql_handle | plan_handle)




09/04/12                                           6
• http://
  msdn.microsoft.com/en-us/library/ms175997(SQL.105).
  aspx
• http://msdn.microsoft.com/en-us/library/ms174276.aspx
• http://blog.miniasp.com/post/2010/05/19/T-SQL-Tips-Fixed-Le
• http://blog.miniasp.com/post/2010/10/13/How-to-get-
  current-executing-statements-in-SQL-Server.aspx
• http://msdn.microsoft.com/en-us/library/ms177648.aspx
• http://msdn.microsoft.com/en-us/library/ms181929.aspx


09/04/12                                                  7
09/04/12   8

More Related Content

PPTX
STACKS IN DATASTRUCTURE
PDF
SQL Subqueries - Oracle SQL Fundamentals
PPTX
Stack of Data structure
PPT
Nested loops
PPTX
Stack - Data Structure
DOC
C# example (Polymorphesim)
PPTX
Stack_Application_Infix_Prefix.pptx
PPTX
Project of data structure
STACKS IN DATASTRUCTURE
SQL Subqueries - Oracle SQL Fundamentals
Stack of Data structure
Nested loops
Stack - Data Structure
C# example (Polymorphesim)
Stack_Application_Infix_Prefix.pptx
Project of data structure

What's hot (20)

PPT
Stacks, Queues, Deques
PDF
STACK ( LIFO STRUCTURE) - Data Structure
PPTX
Stack in Sata Structure
PPSX
Data Structure (Circular Linked List)
PPTX
Mca ii dfs u-3 linklist,stack,queue
PPT
Stack and queue
PPTX
Queue Implementation Using Array & Linked List
PPSX
Data Structure (Double Linked List)
PPTX
Stack Data Structure
PPTX
Stack_Data_Structure.pptx
PPTX
functions and some types
PPT
PPTX
Introduction to stack
PPTX
Stack and Queue
PDF
Stack concepts by Divya
PPTX
queue & its applications
PPTX
Stack and queue
PPTX
Stack project
PPT
Stacks, Queues, Deques
STACK ( LIFO STRUCTURE) - Data Structure
Stack in Sata Structure
Data Structure (Circular Linked List)
Mca ii dfs u-3 linklist,stack,queue
Stack and queue
Queue Implementation Using Array & Linked List
Data Structure (Double Linked List)
Stack Data Structure
Stack_Data_Structure.pptx
functions and some types
Introduction to stack
Stack and Queue
Stack concepts by Divya
queue & its applications
Stack and queue
Stack project
Ad

Similar to 20120810 tsql tips (20)

PPT
Sql performance vesl technologies
PPTX
New T-SQL Features in SQL Server 2012
PDF
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
DOCX
Statements project 2
PDF
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
PDF
Sql wksht-3
PPTX
SQL Server 2012 Best Practices
PPTX
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
PPTX
2 puc cs.pptx bsbshsjshsbbsjsjshdbdbbdbdd
PDF
04-Intro-SQL database management systems
PPS
03 qmds2005 session03
PPTX
SQL.pptx
PDF
SQL Top 10 Interview QnA By Rishabh Mishra in Hindi.pdf
PPTX
Aggregate Function - Database
PPTX
02 database oprimization - improving sql performance - ent-db
PPTX
SQL techniques for faster applications
PDF
Dynamic websites lec2
DOC
ORACLE NOTES
PPTX
Server Query Language – Getting Started.pptx
PDF
advance-sqaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal.pdf
Sql performance vesl technologies
New T-SQL Features in SQL Server 2012
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
Statements project 2
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Sql wksht-3
SQL Server 2012 Best Practices
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
2 puc cs.pptx bsbshsjshsbbsjsjshdbdbbdbdd
04-Intro-SQL database management systems
03 qmds2005 session03
SQL.pptx
SQL Top 10 Interview QnA By Rishabh Mishra in Hindi.pdf
Aggregate Function - Database
02 database oprimization - improving sql performance - ent-db
SQL techniques for faster applications
Dynamic websites lec2
ORACLE NOTES
Server Query Language – Getting Started.pptx
advance-sqaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal.pdf
Ad

More from LearningTech (20)

PPTX
PPTX
PostCss
PPTX
ReactJs
PPTX
Docker
PPTX
Semantic ui
PPTX
node.js errors
PPTX
Process control nodejs
PPTX
Expression tree
PPTX
SQL 效能調校
PPTX
flexbox report
PPTX
Vic weekly learning_20160504
PPTX
Reflection & activator
PPTX
Peggy markdown
PPTX
Node child process
PPTX
20160415ken.lee
PPTX
Peggy elasticsearch應用
PPTX
Expression tree
PPTX
Vic weekly learning_20160325
PPTX
D3js learning tips
PPTX
git command
PostCss
ReactJs
Docker
Semantic ui
node.js errors
Process control nodejs
Expression tree
SQL 效能調校
flexbox report
Vic weekly learning_20160504
Reflection & activator
Peggy markdown
Node child process
20160415ken.lee
Peggy elasticsearch應用
Expression tree
Vic weekly learning_20160325
D3js learning tips
git command

Recently uploaded (20)

PPTX
Machine Learning_overview_presentation.pptx
PDF
Encapsulation theory and applications.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Electronic commerce courselecture one. Pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Machine learning based COVID-19 study performance prediction
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
A Presentation on Artificial Intelligence
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
cuic standard and advanced reporting.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Encapsulation_ Review paper, used for researhc scholars
Machine Learning_overview_presentation.pptx
Encapsulation theory and applications.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Electronic commerce courselecture one. Pdf
Network Security Unit 5.pdf for BCA BBA.
Machine learning based COVID-19 study performance prediction
SOPHOS-XG Firewall Administrator PPT.pptx
Approach and Philosophy of On baking technology
A Presentation on Artificial Intelligence
NewMind AI Weekly Chronicles - August'25-Week II
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
cuic standard and advanced reporting.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Encapsulation_ Review paper, used for researhc scholars

20120810 tsql tips

  • 2. • COUNT(*) •8 • COUNT(Name) •6 • COUNT(DISTINCT Name) •4 09/04/12 2
  • 3. • COUNT(*) • returns the number of items in a group. This includes NULL values and duplicates. • COUNT(ALL expression) • evaluates expression for each row in a group and returns the number of nonnull values. • COUNT(DISTINCT expression) • evaluates expression for each row in a group and returns the number of unique, nonnull values. • Tips • If return values greater than 2^31-1, COUNT produces an error. • COUNT_BIG() 09/04/12 3
  • 4. • REPLICATE • REPLICATE('0', 4 - LEN(3)) + CONVERT(varchar(4), 3) • POWER • RIGHT(CONVERT(varchar(10), POWER(10, 4) + 3), 4) • 10000 + 3 => ‘10003’ • Tips: • POWER ( float_expression , y ) • 數值轉型兩次 (int -> float, float -> varchar) • RIGHT • RIGHT('0000' + CONVERT(varchar(4), 3), 4) • ‘0000’ + ‘3’ => ‘00003’ 09/04/12 4
  • 5. • sp_who2 procedure • 所有連線狀況 , 也可以看到連線是否有被卡住 (Blocked) 的狀況。 09/04/12 5
  • 7. • http:// msdn.microsoft.com/en-us/library/ms175997(SQL.105). aspx • http://msdn.microsoft.com/en-us/library/ms174276.aspx • http://blog.miniasp.com/post/2010/05/19/T-SQL-Tips-Fixed-Le • http://blog.miniasp.com/post/2010/10/13/How-to-get- current-executing-statements-in-SQL-Server.aspx • http://msdn.microsoft.com/en-us/library/ms177648.aspx • http://msdn.microsoft.com/en-us/library/ms181929.aspx 09/04/12 7