Before we move on to our next string function, which is replace, I want to talk about how we can use
a code editor to format our SQL.
This is totally optional.
It really has nothing to do with my SQL, but it does have to do with making our code more readable.
So I showed and I've shown this many times, it doesn't matter how we type a single query.
I mean, it matters in terms of having the right spaces in commas and all the syntax, but in terms
of how we break it up across lines, SQL doesn't care.
But from a human perspective, it should matter.
This is a little tricky to read the way I have it divided here.
So we can format this code.
We don't have to do it ourselves depending on the tool that you're using.
So if I'm using my SQL workbench, this little paintbrush here, I believe.
Come on, show me the hint.
There it is.
Beautify or reformat the SQL script.
If I click that, well, let me make sure I think I have to have this selected.
There we go.
It beautifies it in one way at least.
Remember, there's many different ways of formatting SQL, but this is still better than what I had
before.
As you can see there, it's easier to understand.
But if I do it over here, let's take the same exact code.
But paste it into DB gates.
Just another one of these tools.
I can right click and go to format code and I think I like this one significantly more.
The way that it formats our code in DB gate just looks good to me, indented and all that stuff.
And then we even have something like vs code, just a regular text editor.
I'm working in a SQL file and let me mess this up somewhat so that we have a reason to format it again.
Let's say it's like this.
I'm not a fan of that, so what I can do is open the command palette and if you don't know vs code,
this really isn't worth worrying about, but command shift P And you can click on format, document
or search for format document, but it's probably going to complain that I don't have a SQL formatter
yet.
So here we go.
I'm going to install the one that it suggests SQL formatter.
It's installing now and it should be done.
So let's try that again.
I'm going to format document and I have to change the default formatter.
Sure.
There we go.
And it formatted it for me, so I shouldn't have to go through all those steps.
Next time, let me mess it up again.
Let's say.
I mean, the way I've messed it up here is beyond repair.
I have to have spaces for the actual keywords.
But now I have this set up, so every time I save it auto format, command shift P I can do it manually.
Format document.
This is the shortcut as well.
And there we are.
So it just depends on what text editor you're using or what SQL tool or honestly, you can even just
use a web browser.
If you search online, you can find different code, beautifies fires or SQL for matters.
None of them are terribly pretty, but here's one.
I'll pay some code in.
Let me mess it up again.
Let's do maybe something like that.
Make sure that I tell it I'm using my SQL.
It shouldn't really matter that much.
But let's do that and then format SQL.
And that's how they format it.
I don't know.
I'm not a fan of that one as much.
Let's try this over here.
Same deal.
Paste it in.
And on the right hand side, we see a nice formatted version.
So the moral of the story is that there's a lot of different ways to format code in general.
There's no rule that says it has to be indented or that you have to have separate lines.
It could be a single line of SQL.
But if you are going to format it, I would be consistent in what you use.
And one way to help you be consistent is to find a tool that you like.
So if you're using SQL Workbench, then you can just go with the format that it does for you.
Or if you're using DB Gate or VZ code, or you're just writing your own code on your own.
You're not using any of these editors.
You're working in Microsoft Word.
You could write SQL in Microsoft Word.
As long as you're saving it to a SQL file, then format it using an online tool.
So not a requirement.
And I won't be spending a lot of time formatting my code during the videos, but the end result code
that I share with you will be formatted and should have a consistent pattern or a consistent format.
Next up, we're moving on to more string functions.
Replace.