All posts

2016

SSMS - Connection Color with SQL Prompt & SSMSBoost

If you haven’t explored the visual color coding of tabs based on pattern matches with SQL Prompt, I’d suggest you check this out. Earlier iterations of Red Gate’s SQL Prompt did not change tab color immediately when the connection was changed. Red Gate’s tab color could get out of sync occasionally, so I stopped depending on it.

Apparently this has been improved on and my testing now shows that the tab recoloring for connections is changing when the connection is updated …

  read more

SQL 2016 - Brief Overview on some new features

These are notes taken from the Houston SQL Pass User group from July. This presentation was given by John Cook, (Data Platform Solution Architect Microsoft) who did a great job with limited time on providing some great details on the new functionality with SQL 2016. To follow him, take a look at sqlblog.com where he posts or follow him on twitter. Thanks to him for the overview.

JohnPaulCook (@JohnPaulCook) on Twitter

Microsoft Data Platform specialist and Registered Nurse

John …

  read more

Install ReadyRoll via Command Line

ReadyRoll has some great features, including the ability to use without cost on a build server. If you want to ease setup on multiple build servers you could create a simple command line install step against the EXE.

ReadyRoll was recently acquired by Redgate, so the installer options may change in the future to be more inline with the standard Redgate installer. For now, this is a way to automate an install/updates.

  read more

Does sp_rename on a column preserve the ms_description?

Did some checking as couldn’t find help in the MSDN documentation. My test on SQL 2016 shows that since the column_id isn’t changing, the existing mapping of the description for the column is preserved.

I know it’s probably pretty obvious, but I had someone ask me, so figured proving the mapping for ms_description is maintained would be a good thing to walk through. Score another point for Microsoft, for design practices

  read more

Regex With SQL Server - SQLSharp

In the context of my developer machine, I had log files I wanted to parse through. I setup a log library to output the results on a test server to a sql table instead of text files. However, this meant that my “log viewers” that handled regex parsing weren’t in the picture at this point. I wanted to parse out some columns from a section of message text, and thought about CLR as a possible tool to help this.Ideally, I wanted to feed the results for analysis easily into power bi, …

  read more

Improvements with SSMS 2016

Updated: 2019-01-24
Improved options to install through Chocolatey package. Use command choco upgrade sql-server-management-studio and you’ll simplify the installation process greatly. Also for servers, consider Azure Data Studio as much smaller download and might provide what you need to do basic management without a length install …
  read more

Glasswire: (Giveaway Included) Networking Monitoring even a caveman could

Giveaway details at the bottom for those interestedDealing with development & sql servers, I like to know what type of network traffic is happening on my machine. What is the overhead of monitoring on network bandwidth, what is communicating across servers or even externally?

You can create perfmon counters, but realistically sometimes I just want a easy quick overview of network traffic with minimal overhead. I have been using a utility I came across called …

  read more

SQL Compare 12: Initial Look

I know there have been a few other folks going into more detail on SQL Compare 12 (beta), but I thought I’d share just a few looks at the new design. Looks pretty slick, and I like where the design is going. Just a quick look, as I’m sure there will be more to cover when it’s finally released. Until then….

Very clean. Not too drastic of a change to mess with current workflows. Still, nice to see some clean design like this.

  read more

SSMS Tools Pack - A Handy Tool for generating CRUD

So I’ve had this tool around for a while, but never found much usage out of it to be honest. I didn’t end up writing a review as I had other tools that did text replacements, and history/session saving. I’ve always considered this tools implementation of SQL History/Tabs saver the best period, even over Red Gate Tab History, SSMSBoost, etc. However, recommending the tool solely based on it’s fantastic history saver wasn’t really something I was going to do.However, …

  read more

OmniCompare: A free tool to compare SQL Instances

When working with a variety of instances, you can often deal with variances in configuration that might impact the performance. Without digging into each instance you wouldn’t know immediately that this had happened. There are fantastic tools, like Brent Ozar’s SP_Blitz, but this doesn’t focus on every single configuration value and cross instance comparison. To supplement great material like that a tool like OmniCompare is great.

  read more

Continual Deployment of Visual Studio SqlProj

As a data professional, I’ve never worked extensively with msbuild or other pipelines. I’d been mostly focused on just running schema comparisons and publishing. However, I’ve had the needed to try and deploy a database project from visual studio automatically, and this is my process through it.

There are benefits for those who don’t necessarily want to run this against production, but instead for those …

  read more

The Mysterious Black Box of R - For the SQL Server Guy

Took a class from Jamey Johnston @ SQLSaturday #516 in Houston. Lots of great information covered. Follow him for a much more detailed perspective on R. Jamey Johnston on Twitter @StatCowboy. Did a basic walkthrough of running an R query, and figured I’d share it as it had been a mysterious black box before this. Thanks to Jamey for inspiring me to look at the mysterious magic that is R….

Simple-Talk: Making Data Analytics Simpler SQL Server and R This …

  read more

Red Gate Dependency Tracker - Making Databases Into Moving Art

If anyone thinks that working with complex data structures is boring… I don’t know what world they live in. The problem is often that sql tables and data structures are just script files and lists of tables in an object explorer.

However, once you crack open the visual aspect of database diagramming and data architecture, you can see some interesting patterns emerge.

I’ve long enjoyed playing around with Red …

  read more

Google Search Only Results from the last year

Tech changes quick. Reading google postings from something in 2009 is not my first choice.I found an option after digging through some google discussion posts on how to setup the default search in chrome (also applies to other browsers) to automatically apply the advanced filter option for “results in last year”.

  1. Go to chrome settings menu

  read more

Automating SSMS 2016 Updates & Install

update 2016-04-27 11:20 - Red Gate SQL Toolkit
This also is a great help for folks using Red Gate SQL Toolkits. It can help ensure all items are up to date. When a new bundle installer is identified, it would download the new one and you could then trigger the updates of each of the apps you desire, without having to keep run the download …
  read more

Cool Tools: Powershell ISE-Steroids

Disclaimer: I have been provided with a free license because I am reviewing. This doesn’t impact my assessment of the tool. I have a passion for finding tools that help developers, and even more specifically SQL DBA/Developers improve their workflow and development. I don’t recommend tools without actually using them and seeing if I’d end up adding to my roster of essentials!

Cool Tool: ISE Steroids

Powershell ISE is simple. Not much fluff, but it …

  read more

Failed to Initialize SQL Agent Log... not worthy

Moving system databases in SQL Server takes a bit of practice. I got that again, along with a dose of SQL humility (so tasty!), today after messing up some cleanup with sql agent server log files.

1
Failed to initialize SQL Agent log (reason: Access is denied).

I was creating a sql template when this came about. SQL Server Agent wouldn’t start back up despite all the system databases having very little issues with my somewhat brilliant sql commands. I had moved all my databases to …

  read more

TFS Work-Item Fancy Filtering

If you want to create a TFS query that would identify work items that have changed, but were not changed by the person working it, there is a nifty way to do this.The filtering field can be set to <> another field that is available, but the syntax/setup in Visual Studio is not intuitive. It’s in the dropdown list, but I’d never noticed it before!

  read more

SQL 2012 SP3 and entity framework conflict

An issue with SQL Server 2012 SP3 was identified that impacted EF4/5 due to additional datatypes in the dll.

System.EntryPointNotFoundException: Unable to find an entry point named 'SetClrFeatureSwitchMap' in DLL 'SqlServerSpatial110.dll'

To easily identify the available dll versions of sql server, I ran a quick adhoc bat file.

The output returns a simple text file like this:

  read more

Failover all databases to other server

Quick snippet I threw together to help with failing over synchronized databases to the other server in bulk. No way I want to click that darn Fail-over button repeatedly. This scripts the statements to print (i commented out the exec portion) so that you can preview the results and run manually.Note that it’s also useful to have a way to do this as leaving databases running on the mirror server for an indefinite period can violate licensing terms on the secondary server when it’s a …

  read more

Calculating Some Max Mirror Stats

This turned out to be quite a challenge. I couldn’t find anything that made this very clean and straight forward to calculate, and in my case I was trying to gauge how many mirroring databases I could run on a server.In my scenario, I wasn’t running Expensive Edition (@BrentO coined this wonderful phrase), so was looking for the best way to assess numbers by doing mirroring on a large number of databases, in my case > 300 eventually. The documentation was… well…. a …

  read more

Easy way to test log shipping or availability groups setup

Have been working through the fantastic training resources from Brent Ozar’s Everything Bundle and on the recommended resources they mention after all the training on log shipping and availability groups that you can use a lab environment from TechNet to actually get going on familiarizing yourself with the technology more.

This is great! Of course, it’s not the full deal, but this gives a tangible way to get moving on familiarizing yourself with this complex technology. TechNet …

  read more

Transaction Logging & Recovery (part 3)

Continuation of some notes regarding the excellent content by Paul Randal in Pluralsight: SQL Server: Logging, Recovery, and the Transaction Log. Please consider supporting his excellent material by using Pluralsight and subscribing to his blog. He’s contributed a vast amount to the SQL server community through SQLSkills This is my absorbing of key elements that I never had worked through

Ever seen a picture of a jackalope? Image by …

  read more

Seeker & Servant: Fantastic Music with incredible dynamics

Just recently discovered this artist after being exposed to an article from Worship Leader magazine. Fantastic dynamics. The dynamics and beautiful harmonies are pretty darn close to what I’d love experimenting with if I had a group of folks playing those instruments. Interestingly, the vocal harmonies are very simple, but I found very beautiful. It’s compromised of a tenor and a baritone range, and is a fresh change stuff like Shane and Shane which both have incredibly high ranges. …

  read more

Verifying Instant File Initialization

Ran into a few issues verifying instant file initialization. I was trying to ensure that file initialization was enabled, but found out that running the xp_cmd to execute whoami /priv could be inaccurate when I’m not running it from the account that has the privileges. This means that if my sql service account has different permissions than I do, I could get the incorrect reading on if it is enabled.

Paul Randal covers a second approach using the sysinternals tool Accesschk, which seems …

  read more

Transaction Logging & Recovery (part 2)

Continuation of some notes regarding the excellent content by Paul Randal in Pluralsight: SQL Server: Logging, Recovery, and the Transaction Log. Please consider supporting his excellent material by using Pluralsight and subscribing to his blog. He’s contributed a vast amount to the SQL server community through SQLSkills

  • The initial size of the log file is the larger of 0.58 MB or 25% of the total data files specified in the create database statement. For example, …
  read more

Transaction Logging & Recovery (101)

Logging & Recovery Notes from SQL Server Logging, Recovery, and the Transaction Log (pluralsight) Paul Randal Going to share some key points I’ve found helpful from taking the course by Paul Randal at pluralsight. I’ve found his knowledge and in detail presentation extremely helpful, and a great way to expand my expertise. Highly recommend pluralsight.com as well as anything by Paul Randal (just be prepared to have your brain turned to mush… he’s definitely not …

  read more

2015

Model needs exclusive lock

Ran into an issue where a developer was trying to create a database and was denied due to no ability to obtain exclusive lock on model. After verifying with other blogs, I found that creating a database required exclusive lock to use model as a template for the new database creation.

In my case I had connected with SSMS directly to model for some queries instead of master. In this case, SQL Complete (Devarts’s excellent alternative to SQL Prompt) was querying the schema had this open …

  read more

Documenting Your Database with Diagrams

Don’t get too excited. I know you love documentation, and just can’t wait to spend some time digging in to document your database thoroughly. I imagine you probably want to build visio charts manually, or draw whiteboard diagrams by hand and take pictures.

For the rest of us that are lazy, a tool to help document your database is a great idea. I’m a big fan of SQL Doc by Red Gate, and ApexSQL Doc . I ended up using ApexSQL doc to document the database at my work, though Red …

  read more

Best Tools for Taking Notes In Development

Updated: 2016-04-08
Been working through some issues with Clarify app on my personal computer, something I messed up. @trevordevore with @clarifyapp has worked step by step through it with me providing some great personal assistance. In addition, he’s given me some tips about my research in merging in a php script to automatically …
  read more

Dynamic SQL & Quotename

Quotename can be a pretty cool function to simplify your dynamic sql, as it can ease some of the escaping of strings. However, I normally use it for table/column names, and so hadn’t ran into a “gotcha” of this function until today. It’s limited to 128 characters, and if you pass in greater than 128 characters will yield a null. Yep… you could be trying to track down that error for a null string somewhere in your …

  read more

XML Attribute VS Element Assignment when working with SQL

I find it interesting the difference in behavior with querying XML between column assignment, and quoted alias naming. It’s a generally understood best practice to not use the deprecated syntax of column aliasing using a quoted name. For example:

1
2
3
4
5
6
select
    [escapedWithBracketsIsGood] = case when raining then cats else dogs end
    ,NoEscapeNeededPerGoodNamingPractices = case when rains then pours else friday end
    ,case when writtenThisWay …
  read more

Split personality text editing in SSMS with Sublime Text 3

My preview post showed a demonstration of the multi-cursor editing power of Sublime Text 3 when speeding up your coding with SQL server.There is a pretty straight forward way to setup sublime (or one of your preferred text editors) to open the same file you are editing in SQL Management Studio without much hassle. I find this helpful when the type of editing might benefit from some of the fantastic functionality in Sublime.

Go to Tools > External Tools

  read more

Multi-Cursor Editing SQL feels like the movie Inception just became real

  • Yes… multicursor editing is epic
  • No… SSMS doesn’t support multi-cursor editing the way it should.
  • Yes… you can do some basic editing with multiple lines using alt-shift
  • No… it doesn’t come close to what you can do with Sublime. Cool thing is you can open text in Sublime synced w/SSMS cursor position and switch between the two with a shortcut. That will be a post for another day, I’m just telling you now to get your appetite going. If you can’t …
  read more

Brentozar''s Training: Chocolate & Cowboy Hats Included

It was entertaining to listen to a technical wizard fighting the obsession with waiting to eat chocolate with 3k viewers watching. Kendra wore about 4-5 cowboy hats in an effort to help those of us who wear many hats feel welcome…. Now that’s the kinda of training I enjoy! No pretense, just honest real, and insightful training with enjoyable humor included for free

Highly recommend attending the webex presentations occurring today and tomorrow with Brent Ozar and his amazing team. …

  read more

Monitoring SQL Server on a budget

There’s a lot of tools out there, and very few that are polished, have a good UI, and some reasonable functionality to help monitoring, that don’t cost an arm and a leg. One such tool I’ve recently begun to appreciate is MiniDBA . I was generously provided with a license to evaluate this and continue testing, and have recently had an actual chance to start using it more in my environment. The cost for MiniDBA is one of the most affordable I’ve …

  read more

Stranger Danger... The need for trust with constraints

I ran into an issue with errors with an database upgrade running into a violation of a foreign key constraint. Don’t know how it happened. Figured that while I’m at it, I’d go ahead and evaluate every single check constraint in the database to see if I could identify any other violations, because they shouldn’t be happening.

In my reading, I found out that checking the constraints can enable the constraint to be marked …

  read more

Red Gate SQL Source Control v4 offers schema locks

Looks like the rapid release channel now has a great feature for locking database objects that you are working on. Having worked in a shared environment before, this could have been a major help. It’s like the poor man’s version of checking an object out in visual studio except on database objects! With multiple developers working in a shared environment, this might help reduce conflicting multiple changes on the same object.

Note that this doesn’t look to evaluate dependency …

  read more

Using Qure Profiler To Benchmark Tuning Progress

Qure Analyzer Benchmark Testing

Updated 2018-03-18
Wouldn’t recommend tool at this time. Development seemed to cease, resulting in me not being able to use with later versions of SQL Server. When I came back recently to check on it, the app was sold and it was with a new company. Didn’t see to have progressed …
  read more

SET NOEXEC is my new friend

Have never really played around with the option: SET NOEXEC ON Turns out this can be a helpful way to validate larger batch scripts before actually making changes, to ensure compilation happens. If you choose, you can verify syntax by “parsing” in SSMS. However, this doesn’t compile. Compilation checks more than your syntax. It actually validates the objects referenced exist.

The execution of statements in SQL Server has two phases: compilation and execution. This setting is …

  read more

Running very large scripts is not a strong area for SSMS

Am I the only one that has experienced the various out of memory issues with SSMS? Not according to google!

I’ve a huge fan of Devarts products. I’ve done a review in the past on their SQL Complete addin, which is the single most used tool in my SQL arsenal. It vanquishes nasty unformatted code into a standard lined up format I can easily read. The 100’s of options to customize the …

  read more

Database Stuck in Single-User Mode Due to Botched Restore

Working in a development environment, I botched up a restore. After this restore attempt to overwrite my database with the previous version, I had it stuck in single-user mode.

SSMS provided me with helpful messages such as this: Changes to the state or options of database 'PoorDb' cannot be made at this time. The database is in single-user mode, and a user is currently connected to it. Additionally, I was told I was the deadlock victim when attempting to set the user mode back to multi-user. …

  read more

What was I thinking? Deleting myself from localdb?

Was testing a batch file to add a user to a localdb instance. Assumed that my user as admin on the machine wouldn’t have an issue inserting myself back…. didn’t think that one through too carefully. Executing any type of SQLCMD against it denied me. SSMS denied me. No SA had been setup on it, so I couldn’t login as SA either. Looked for various solutions, and ended up uninstalling and reinstalling (localdb)v11.0 so that I’d stop having myself denied permissions. …

  read more

Enabling Instant File Initialization

Found a couple good walkthroughs on enabling instant file initialization. However, I’m becoming more familar with the nuances of various setups and found it confusing in trying to map the correct user/group to enable this option. In my case, I had the SQL Service running under NT SERVICE/MSSSQLSERVER and as such this logic wasn’t showing up when trying to find groups/users to add to the necessary permissions. Lo and behold…

I typed it in manually and it worked. If time permits …

  read more

Upgrade from SQL 2014 Evaluation to Developer Edition

Couldn’t find documentation showing that upgrade from SQL 2014 evaluation version was possible to developer edition. I just successfully converted an evaluation version to developer edition.

  1. Obtain the key for the developer edition (in my case I had to download the .ISO from MSDN downloads, and go through the installation wizard to get it)
  2. Run the installation center app for SQL Server 2014
  3. Select edition upgrade
  4. Plug in your new serial from the developer edition. Pretty simply, but …
  read more

Utilizing the power of table parameters to reduce IO, improve performance, decrease pollution, and achieve world peace...

I was dealing with a challenging dynamic sql procedure that allowed a .NET app to pass in a list of columns and a view name, and it would generate a select statement from this view. Due to requirements at the time, I needed the flexibility of the “MAIN” proc which generated a dynamic select statement, while overriding certain requested views by executing a stored proc instead of the dynamic sql.

During this, I started looking into the string parsing being completed for a comma …

  read more

SQL Sentry Pro Explorer is worth it...

Updated: 2017-04-21
Another great bit of news from reviewing this older post I wrote… SQL Sentry Pro is now a free tool thanks to the generosity of the Sentry One team! It’s a must have. Go download it for sure.
  read more

Restoring a database that doesn't exist

When restoring a database that doesn’t exist, say for instance when a client sends a database to you, you can’t use the option to restore database, because there is no database matching to restore. To get around this you need to use the Restore Files and Filegroups option and then restore the database.

  read more

Statistics Parsing

Never really enjoyed reading through the statistics IO results, as it makes it hard to easily guage total impact when you have a long list of tables. A friend referred me to: http://www.statisticsparser.com/ This site is great! However, I really don’t like manually copying and pasting the results each time. I threw together a quick autohotkey script that will detect your clipboard change event, look for “scan count” keyword, and then open a “chrome app”, paste the …

  read more

Dev Tools: The File Searcher/Launcher to rule them all

Why does this not have more recognition? In the experimentation of various file management and launching apps, I’ve tried several (Launchy, Listary, etc), but none have offered the speed and customization of Find and Run Robot. This app is a life saver for the power user! Here is an example of how you can have a hotkey to immediately launch a customized google search. The group alias gives you extensibility to filter the text you are typing to identify this alias of “Google Me” …

  read more

Case of the Mondays... causing me to randomly redefine the Scope of Global

Today, I was reminded that global temp tables scope lasts for the session, and doesn’t last beyond that. The difference is the scope of the global temp allows access by other users and sessions while it exists, and is not limited in scope to just the calling session. For some reason I can’t remember, I had thought the global temp table lasted a bit longer. Remembering this solved the frustration of wondering why my adhoc comparison report was empty….. #mondayfail SQLMag …

  read more

2014

Dev Tools: XYplorer (review 1) - Catalog

currently on version 14.60 I’m a big fan of finding tools that help automate and streamline things that should are routine actions.Surprisingly, I’ve found it incredibly challenging to move away from the default Windows Explorer for file management, as the familiarity it offers makes it somewhat tough to be patient with learning an alternative, especially if the alternative offers more complication. That’s where I stood with XYPlorer for sometime. It is a developer’s tool …

  read more

OR pattern causing indexing scans in parameter based queries

#Tl;dr

(time constraints prevented me from reworking significantly)

“or-condition-performance” article on SQL Server Pro was forwarded over to me to research by a friend who indicated that using a variable with an or pattern had historically caused table scans. This was a suprise to me as all previous queries with optional parameters I’d used in the past seemed to use index seeks. I had to dig into this a little deeper to see if had been missing this in my past work and needed …

  read more

Generate Random Date With Starting Point

If you want to create sample random samples when dealing with date calculations to test your results, you can easily create a start and end point of randomly created dates. This is a snippet I’ve saved for reuse:

DATEADD(day, (ABS(CHECKSUM(NEWID())) % $Days Seed Value$), '$MinDate$')

This should let you set the starting point (Min Date) and choose how far you want to go up from there as a the seed value. Ie, starting point 1/1/2014 with seed of 60 will create random dates up to 60 days …

  read more

Finding Groups - Consecutive Months

A step by step explanation on one way to get a consecutive period of months, which could easily be adapted to days, years, or other values. I’ll continue on this track and post a tutorial on eliminating overlapping dates soon.

Eliminate Overlapping Dates

I was looking for an efficient way to eliminate overlapping days when provided with a historical table that provided events that could overlap. In my case, I had dates show the range of a process. However, the multiple start and end dates could overlap, and even run concurrently. To eliminate double counting the days the process truly was in play I needed a way to find eliminate the overlap, and eliminate duplicate days when running in parallel. I researched ways to complete this and found the …

  read more

Scalar functions can be the hidden boogie man

Ran across a comment the other day that scalar functions prohibit parallelism for a query when included. I thought it would be worth taking a look, but didn’t take it 100% seriously. Came across the same indication today when reviewing MVP deep dives, so I put it to the test.Turns out even a simple select with a dateadd in a scalar format was affected enough with that one action to drop 5% on the execution plan. When dealing with merge or other processes that would benefit from …

  read more

2013

Shortcut to reference examples, syntax, and definitions straight from SSMS

I’ve never really used the F1 key for help files with most applications. I was surprised at the usefulness in SSMS I discovered today that uses scripting to actually get you MSDN articles relevant to your current selection in the query editor.

If you have a keyword selected and want to view details, definition, and examples on it, you can highlight the phrase or select the word, press F1, and SSMS will pull up the appropriate MSDN article. The only issue I ran into was that it pulls up the …

  read more

Check Constraints can help enforce the all or nothing approach when it comes

If you have a set of columns inside your table that you want to allow nulls in, however if one of the columns is updated force all columns in the set to be updated, use a check constraint. In my case, I had 3 columns for delete info, which were nullable. However, if one value was updated in there, I want all three of the delete columns to require updating. I created the script below to generate the creation and removal of these constraints on a list of tables:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11 …
  read more

TSQL Snippet for viewing basic info on database principals and their permissions

Quick snippet I put together for reviewing basic info on database users/principals, permissions, and members if the principal is a role.:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*******************************************************
    Some Basic Info on Database principals, permissions, explicit permissions, and if role, who is in …
  read more

View computed columns in database

Snippet to quickly view computed column information. You can also view this by doing a “create table” script. This however, was a little cleaner to read and view for me.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13

select
    database_name = db_name()
    ,object_schema_name = object_schema_name( object_id )
    ,object_name = object_name( object_id )
    ,full_object_name = object_schema_name( object_id ) + '.' + object_name( object_id )
    ,column_name = name
    ,cc. …
  read more

On how to Googlify your SQL statements for future searching

For sake of future generations, let’s begin to reduce typing and reuse code we’ve built. I think we can all agree that TSQL statements are often repeated. Ideally, snippets should be created to reduce repeated typing and let us focus on logic and content. However, some statements may not really be “snippet worthy”, and just be quick adhoc queries. In the past, the solution for saving queries for reuse or reference in the future would be to just save in the projects folder …

  read more

Get synonym definitions for all databases in server

If you want to audit your enviroment to look at all your synonyms and see where they are pointing, you can use exec sys.sp_MSforeachdb to loop through databases, and even filter. It will save some coding. However, my research indicates it is probably a bad practice to rely on this undocumented function as it may have issues not forseen and fully tested.

Additionally, support may drop for it in the future. I recreated what I needed with a cursor to obtain all the synonym definitions into a temp …

  read more

Calculating the next beginning of month and the current end of month

Handling dates is always a fun challenge in T-SQL! Finding the current end of month and next months beginning of month is straight forward, but I like to find new ways to do things that take less coding, and hate date conversions that require a lot of manipulation of characters and concatenation. This was what I came up with for avoiding character conversions and concatenation for finding the current BOM (beginning of month) and EOM (end of month) values. Adjust according to your needs. Cheers! …

  read more

Installing SSMS 2012 all by it's lonesome

SQL Server Management Studio (SSMS) is not offered as a standalone download on MSDN. Installation requires the user to download the sql server installation package and choose to install only this single feature. For developers, SQL Developer edition is a great choice.

Here’s some screenshots to give you a guide on installing SSMS by itself when working with the full installer.

  read more

snippet designate a certain time of the day in getdate()

Snippet to designate a certain time of the day to evaluate in the current day. If you need to limit a result to the current date after a particular time, strip the time out of the date, and concatenate the current time together with it, and then convert back to datetime2.

1
select convert(datetime2(0),cast(cast(getdate() as date) as varchar(10)) + ' 09:00 ')
  read more

Native SSMS a second class citizen no longer...

Intellisense can be a boon to adding quick development. Quick hints on scope specific variables, syntax suggestions, function descriptions and more provide a valuable tool to productive coding.Coding in SQL Server Management Studio (SSMS) has greatly improved over the version releases, but it still lags behind the power of Visual Studio’s intellisense, template insertions with “fill in the blank” functionality .

Additionally, the lack of automatic indentation means that lining …

  read more

dynamic sql and a char crash

Dynamic SQL can be helpful, but a pain to debug. I spent hours today working on figuring out why my simple date comparison in dynamic SQL wasn’t working. Found out that the remote database I was connecting to had a char date instead of a datetime. I found the comparison of CHARDATE > VARCHARDATE failed to error out, but also failed to give a proper result set. Changing the look-up to ensure both dates were converted to date fixed the issue. During this debugging I was reviewing my …

  read more

How to default SSRS date parameters to the first and last day of the the previous month

Populating default dates in SSRS can be helpful to save the user from having to constantly input the date range they normally would use. When a report is pulled for last month’s information, defaulting the date fields for the user can help streamline their usage of the report, instead of them manually selecting with the date-picker control in SSRS. The formula’s I used were:

1
2
3
Beginning of Current Month (EOM) DateSerial(Year(Date.Now), Month(Date.Now), 1)
Beginning of Last …
  read more