4. SSMS: Comment Shortcut Key
CTRL-K, C
CTRL-K, U
--select * from sales.customers c
--join sales.orders o
--on c.custid = o.custid
5. Three Ways to Search Schema:
F7
Object Explorer Details select object_name(object_id), definition as name
from sys.all_sql_modules
where definition like '%cust%'
26. T-SQL: Testing and Refactoring with EXCEPT Keyword
;with FreightTotal
as
(
select custid, sum(freight) as totalFreight
from sales.orders
group by custid
)
select o.custid
, o.freight
, ft.totalFreight as totalFreight
from sales.orders o
join FreightTotal ft
on o.custid = ft.custid
EXCEPT
select custid
, freight
, sum(freight) over (partition by custid) as totalFreight
27. T-SQL: Life is so easy with a dates table
Find the sales numbers for the first Monday of
every month of the year
T-SQL with no dates table
T-SQL with dates table
35. T-SQL: Check for heaps/clustered indexes
SELECT t.[Name] FROM sys.Indexes i
JOIN sys.Tables t
ON t.Object_ID = i.Object_id
WHERE i.type_desc = 'HEAP'
ORDER BY t.[Name]
36. T-SQL: Index all the keys
select object_name(c.object_id), c.name from
sys.columns c
where c.name like '%id'
and c.object_id not in
(
select object_id
from sys.index_columns
)
38. SSRS: Log, Log, Log (and beware of
subscriptions)
select c.Name
, e.InstanceName
, e.UserName
, e.Parameters
, e.TimeStart
, e.TimeEnd
, e.TimeDataRetrieval
, e.TimeProcessing
, e.TimeRendering
from executionlog e
join catalog c
on e.reportid = c.ItemID
Send a Link, or a file on a shared folder that you can audit. Find someway to audit
who opened the link or the file in the folder. Try to avoid sending the PDF without a
way to audit it.
39. SSRS: Store colors in the database
Colors = Business Logic
Put it in the database
Use Expressions to read the colors
Include action colors and levels
42. SSRS: Get Buy-in to Export to Single Format
• Build to export to a single format
• Excel
• Word
• Web
• PDF
• Then get buy-in and make it a standard in the
organization
43. SSRS: Used Linked Reports to Manage
Security
• Allows you to use Role
assignments and
• Not have duplicate reports in
folders
• Not have users in folders they
shouldn’t be in
• Not manage security on
individual reports
44. SSRS: Use a report footer
• Put executive sponsor there & email address
• Date Executed
• Parameters Used
• Date Created
• Date Modified
• Put row count there
45. SSRS: Use a wiki for taxonomy
Record owner
Record changes
Record technical calculation
48. Power BI - Visualization: Use color sparingly.
In nature, colors do two things:
1) Entice
2) Warn
So let’s use them sparingly..
WARNING: POISON FROG!
54. Power BI: Use bookmarks to create a portal
• https://www.blue-granite.com/blog/create-an-app-like-experience-
in-power-bi-with-bookmarks
55. Power BI: Text To Image Converter
• https://www.branah.com/text-to-image
56. Power BI: Use bookmarks for pagination
• https://community.powerbi.com/t5/Data-Stories-Gallery/Pagination-
in-Power-BI-Reports-utilizing-Bookmarking/td-p/325702
61. Wrapping Up: Keep Report Quantity Small
Too many reports means that there are more things to
keep consistent
Reports that aren’t used, tend to get forgotten, and then
used with bad data
63. Wrapping Up: Find the key person
• They know a lot
• They have time
• They respond quickly
• They are most often right
• They might not be likeable,
and that’s OK
• Success – Work in their
office
64. Wrapping Up: Change one thing at a time
And break calculations down to their
simplest form, deploy, test, and change
one more thing.
65. Wrapping Up: Very few KPIs and numbers!
"The well-intentioned desire to be great at everything
is precisely what leads to exhausted mediocrity"
https://www.youtube.com/watch?v=DWKvSG_9s5I"
Walmart customer service
66. Wrapping Up: Use friendly names everywhere
Use spaces and long names
68. Wrapping Up: Have the child call you
Whenever someone comes around saying "Would you like to buy
blah blah blah, my kid is going to do whatever."
I tell them, "Yes, I would love to! But your child has to be the one to
ask me." I then give them my number and say the child can call
anytime after 6pm.
73. Just like Jimi Hendrix …
We love to get feedback
Please complete the session feedback forms
74. SQLBits - It's all about the community...
Please visit Community Corner, we are trying this year to get more
people to learn about the SQL Community, equally if you would be
happy to visit the community corner we’d really appreciate it.
Editor's Notes
update sales.customers
set contacttitle = null
where custid in ('59', '66', '78', '15')
use tsql2012
select * from sales.customers
select ContactName
+ ' - ' + ContactTitle
+ ', ' + City as GreetingLine
from sales.customers
select isnull(ContactName, '')
+ ' - ' + isnull(ContactTitle, '')
+ ', ' + isnull(City, '') as GreetingLine
from sales.customers
select concat(ContactName, ' ', ContactTitle, ' ', City) as GreetingLine
from sales.customers
use tsql2012
select *
from sales.orders
select custid, freight
from sales.orders
select custid, freight, sum(freight) as totalFreight
from sales.orders
select custid, sum(freight) as totalFreight
from sales.orders
group by custid
select custid, freight, sum(freight) as totalFreight
from sales.orders
group by custid
select custid, freight, sum(freight) as totalFreight
from sales.orders
group by custid, freight
--we're skipping subqueries, because they look ugly and
--it insults me aesthetically
;with FreightTotal
as
(
select custid, sum(freight) as totalFreight
from sales.orders
group by custid
)
select o.custid
, o.freight
, ft.totalFreight as totalFreight
from sales.orders o
join FreightTotal ft
on o.custid = ft.custid
--BIG IMPROVEMENT
--query can be executed independantly
--Can be reused, like this
;with FreightTotal
as
(
select custid, sum(freight) as totalFreight
from sales.orders
group by custid
)
select o.custid
, o.freight
, ft.totalFreight as totalFreight
, o.freight /ft.totalfreight * 100 as FreightPercentage
from sales.orders o
join FreightTotal ft
on o.custid = ft.custid
--but remember our original thought process
select custid, freight, sum(freight) as totalFreight
from sales.orders
--here's a windowing function
select custid
, freight
, sum(freight) over (partition by custid) as totalFreight
from sales.orders
--and reusing it is not that big of a deal
select custid
, freight
, sum(freight) over (partition by custid) as totalFreight
, freight / sum(freight) over (partition by custid) * 100 as FreightPercentage
from sales.orders
;with FirstMondays
as
(
Select DateAdd(day, (9-DatePart(weekday,
DateAdd(Month, 1+DateDiff(Month, 0, '12/1/2009'), 0)))%7,
DateAdd(Month, 1+DateDiff(Month, 0, '12/1/2009'), 0)) as FirstMonday
union all
select DateAdd(day, (9-DatePart(weekday,
DateAdd(Month, 1+DateDiff(Month, 0, FirstMonday), 0)))%7,
DateAdd(Month, 1+DateDiff(Month, 0, FirstMonday), 0))
from FirstMondays
where firstMonday <= '12/1/2010'
)
select * from FirstMondays
use adventureworksdw2012
select EnglishMonthName, min(datekey)
from dimdate
where englishdaynameofweek = 'monday'
and calendaryear = '2010'
group by EnglishMonthName, MonthNumberOfYear
order by MonthNumberOfYear
SELECT * FROM (SELECT urgency, name, phone, location, department, cc, status, case_manager, ip, case_manager_ei d, id_problem, id_problem_type, eid_author, title, body, date_created, date_modified FROM problems AS main INNER JOIN (SELECT id_problem as t_urgency_id_problem, node_value AS urgency FROM problem_nodes WHERE node_name = "urgency")t_urgency ON t_urgency.t_urgency_id_problem = main.id_problem INNER JOIN (SELECT id_problem as t_name_id_problem, node_value AS name FROM problem_nodes WHERE node_name = "name")t_name ON t_name.t_name_id_problem = main.id_problem INNER JOIN (SELECT id_problem as t_phone_id_problem, node_value AS phone FROM problem_nodes WHERE node_name = "phone")t_phone ON t_phone.t_phone_id_problem = main.id_problem INNER JOIN (SELECT id_problem as t_location_id_problem, node_value AS location FROM problem_nodes WHERE node_name = "location")t_location ON t_location.t_location_id_problem = main.id_problem INNER JOIN (SELECT id_problem as t_department_id_problem, node_value AS department FROM problem_nodes WHERE node_name = "department")t_department ON t_department.t_department_id_problem = main.id_problem INNER JOIN (SELECT id_problem as t_cc_id_problem, node_value AS cc FROM problem_nodes WHERE node_name = "cc")t_cc ON t_cc.t_cc_id_problem = main.id_problem INNER JOIN (SELECT id_problem as t_status_id_problem, node_value AS status FROM problem_nodes WHERE node_name = "status")t_status ON t_status.t_status_id_problem = main.id_problem INNER JOIN (SELECT id_problem as t_case_manager_id_problem, node_value AS case_manager FROM problem_nodes WHERE node_name = "case_manager")t_case_manager ON t_case_manager.t_case_manager_id_problem = main.id_problem INNER JOIN (SELECT id_problem as t_ip_id_problem, node_value AS ip FROM problem_nodes WHERE node_name = "ip")t_ip ON t_ip.t_ip_id_problem = main.id_problem INNER JOIN (SELECT id_problem as t_case_manager_eid_id_problem, node_value AS case_manager_eid FROM problem_nodes WHERE node_name = "case_manager_eid") t_case_manager_eid ON t_case_manager_eid.t_case_manager_eid_id_problem = main.id_problem)t
create table t1
(col1 varchar(100))
insert into t1
(col1)
values
('1')
,('2')
,('3')
,('ike')
,('1')
,('2')
,('3')
,('ike')
, ('1')
,('2')
,('3')
,('ike')
select cast(col1 as int) from t1
select try_cast(col1 as int) from t1