August 21, 2015 at 6:05 am
Brandie Tarvin (8/21/2015)
Phil Parkin (8/21/2015)
Ah yes, tried to take a sneaky shortcut. Needs to be fixed:and sjh.run_date >= (year(getdate() - 1) * 10000 + month(getdate() - 1) * 100 + day(getdate() - 1));
That's an interesting way of dealing with the date stuff in the sys tables. I hadn't thought about that. Thanks, Phil.
I don't think I've ever seen that approach before. It's SARGable and definitely has me thinking about it. Thanks.
August 21, 2015 at 6:36 am
Ugh. Wife has my summer cold, kept both of us up last night with her coughing...
So now I'm at my desk trying not to doze off, and the coffee isn't helping...
On a lighter note, I managed to work my way through how PIVOT works (I think I did this once before, but it's been a while) to generate an easy to understand "last backup completed" query.
Which I'm planning to use with my boss to try to push for a better backup solution than what we're using right now...
It really, really shouldn't take upwards of 12 hours to backup one lousy 40GB database...
August 21, 2015 at 6:39 am
THREADIZENS!
Your knowledge is needed. I've got an idea for an article. It's meant to be a basics article for introductory level people. I want to put together that standard list of 10 or 20 T-SQL statements that you run very frequently. The stuff you just have to trip out of your finger tips without thinking about syntax. But not SELECT * FROM. I mean DBA stuff. For example, I must run this one 5-10 times a day:
BACKUP DATABASE X TO DISK = 'E:\x.bak';
RESTORE, I don't do as much, but it would make the list. DBCC SHOW_STATISTICS, all the time. There are others. I'm just looking for the straight-forward T-SQL commands that you just know because you've done them so often.
My ask (to use evil Microsoft-speak) is that you, some of the best DBAs I know, without worrying about duplication, give me five of your most common commands or scripts or statements. I'll compile everything down to between 10 & 20 of the most common for an article.
Does that work?
Don't post yet though. I'll put this out as a question to SSC in general just to see if we get other responses too.
Oh, and nothing proprietary. I don't want to get copies of Ola's scripts or spBlitz or spWhoIsActive. OK?
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
August 21, 2015 at 6:55 am
Ed Wagner (8/21/2015)
Brandie Tarvin (8/21/2015)
Phil Parkin (8/21/2015)
Ah yes, tried to take a sneaky shortcut. Needs to be fixed:and sjh.run_date >= (year(getdate() - 1) * 10000 + month(getdate() - 1) * 100 + day(getdate() - 1));
That's an interesting way of dealing with the date stuff in the sys tables. I hadn't thought about that. Thanks, Phil.
I don't think I've ever seen that approach before. It's SARGable and definitely has me thinking about it. Thanks.
I personally prefer this:
and sjh.run_date >= CONVERT( char(8), getdate()- 1, 112)
It will do an implicit conversion of the expression from char to int, so it's still SARGable. I'm not sure if it does an impact on performance or not, but it's simpler.
August 21, 2015 at 7:06 am
Luis Cazares (8/21/2015)
Ed Wagner (8/21/2015)
Brandie Tarvin (8/21/2015)
Phil Parkin (8/21/2015)
Ah yes, tried to take a sneaky shortcut. Needs to be fixed:and sjh.run_date >= (year(getdate() - 1) * 10000 + month(getdate() - 1) * 100 + day(getdate() - 1));
That's an interesting way of dealing with the date stuff in the sys tables. I hadn't thought about that. Thanks, Phil.
I don't think I've ever seen that approach before. It's SARGable and definitely has me thinking about it. Thanks.
I personally prefer this:
and sjh.run_date >= CONVERT( char(8), getdate()- 1, 112)
It will do an implicit conversion of the expression from char to int, so it's still SARGable. I'm not sure if it does an impact on performance or not, but it's simpler.
It's straightforward and easily understood without needing a second look. Oh boy...I see a performance test in my future. I don't know if I could continue without knowing. π Less functions would suggest faster execution, but we'll see.
August 21, 2015 at 7:12 am
ChrisM@Work (8/21/2015)
Sean Lange (8/20/2015)
Luis Cazares (8/20/2015)
Lynn Pettis (8/19/2015)
Silver spoon, silver spoon, silver spoon, when are you going to admit you are in over your head and really need to find a different career.I was really surprised with this post and then by the questions made by this person in previous threads.
http://www.sqlservercentral.com/Forums/Topic1713458-3077-1.aspx
The urge to pile on for that question was strong. So sad they have to post how to "fix" that query. Obvious they have absolutely no idea how the current query works at all.
There have been a few of those this week. The temptation to say "You really don't have a clue how this works do you?" can become overwhelming. Just think back to when you were constructing some C# to pick up filenames in a SSIS package and how awful and humbling it felt to be a noob again.
And that is exactly why I said nothing and walked away.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 β Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 21, 2015 at 7:15 am
If you want to help out, here's the thread.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
August 21, 2015 at 7:21 am
Ed Wagner (8/21/2015)
Luis Cazares (8/21/2015)
Ed Wagner (8/21/2015)
Brandie Tarvin (8/21/2015)
Phil Parkin (8/21/2015)
Ah yes, tried to take a sneaky shortcut. Needs to be fixed:and sjh.run_date >= (year(getdate() - 1) * 10000 + month(getdate() - 1) * 100 + day(getdate() - 1));
That's an interesting way of dealing with the date stuff in the sys tables. I hadn't thought about that. Thanks, Phil.
I don't think I've ever seen that approach before. It's SARGable and definitely has me thinking about it. Thanks.
I personally prefer this:
and sjh.run_date >= CONVERT( char(8), getdate()- 1, 112)
It will do an implicit conversion of the expression from char to int, so it's still SARGable. I'm not sure if it does an impact on performance or not, but it's simpler.
It's straightforward and easily understood without needing a second look. Oh boy...I see a performance test in my future. I don't know if I could continue without knowing. π Less functions would suggest faster execution, but we'll see.
That's an advantage of working with databases that use character and integer dates. You get creative on the simplest forms to work with them.
August 21, 2015 at 7:23 am
Luis Cazares (8/21/2015)
Ed Wagner (8/21/2015)
Brandie Tarvin (8/21/2015)
Phil Parkin (8/21/2015)
Ah yes, tried to take a sneaky shortcut. Needs to be fixed:and sjh.run_date >= (year(getdate() - 1) * 10000 + month(getdate() - 1) * 100 + day(getdate() - 1));
That's an interesting way of dealing with the date stuff in the sys tables. I hadn't thought about that. Thanks, Phil.
I don't think I've ever seen that approach before. It's SARGable and definitely has me thinking about it. Thanks.
I personally prefer this:
and sjh.run_date >= CONVERT( char(8), getdate()- 1, 112)
It will do an implicit conversion of the expression from char to int, so it's still SARGable. I'm not sure if it does an impact on performance or not, but it's simpler.
Nice! Same execution plans for each method, and yours is neater.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
August 21, 2015 at 7:31 am
Phil Parkin (8/21/2015)
Luis Cazares (8/21/2015)
Ed Wagner (8/21/2015)
Brandie Tarvin (8/21/2015)
Phil Parkin (8/21/2015)
Ah yes, tried to take a sneaky shortcut. Needs to be fixed:and sjh.run_date >= (year(getdate() - 1) * 10000 + month(getdate() - 1) * 100 + day(getdate() - 1));
That's an interesting way of dealing with the date stuff in the sys tables. I hadn't thought about that. Thanks, Phil.
I don't think I've ever seen that approach before. It's SARGable and definitely has me thinking about it. Thanks.
I personally prefer this:
and sjh.run_date >= CONVERT( char(8), getdate()- 1, 112)
It will do an implicit conversion of the expression from char to int, so it's still SARGable. I'm not sure if it does an impact on performance or not, but it's simpler.
Nice! Same execution plans for each method, and yours is neater.
Yes, the execution plans are identical, as are the reads and execution time. I've run it over several data sets and everything is identical. Very nice. Thanks to the both of you.
August 21, 2015 at 7:57 am
I had someone ask recently about seeing more dev articles, especially T-SQL based ones. Anyone up for doing some one-pagers that solve some of the things you've done in the forums?
August 21, 2015 at 7:57 am
Steve Jones - SSC Editor (8/21/2015)
I had someone ask recently about seeing more dev articles, especially T-SQL based ones. Anyone up for doing some one-pagers that solve some of the things you've done in the forums?
Absolutely.
August 21, 2015 at 8:05 am
Steve Jones - SSC Editor (8/21/2015)
I had someone ask recently about seeing more dev articles, especially T-SQL based ones. Anyone up for doing some one-pagers that solve some of the things you've done in the forums?
Probably (though I don't tend to answer too many questions requiring queries to be written any longer), but not until November. Got outstanding article for Tony, two for you, at least one editorial for Tony.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 24, 2015 at 1:37 am
I'd like to nominate Steve Munson for an honorary SSC sainthood for his handling of the OP in this thread. Steve stuck with it through to the end when mere mortals - including me - dropped out in frustration with the OP's peculiar logic, stubborn refusal to answer questions and maddening Reverse Polish communication style. Top work.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 15 posts - 50,311 through 50,325 (of 66,712 total)
You must be logged in to reply to this topic. Login to reply