From the course: SQL Server Fundamentals: Master Basic Query Techniques

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Case statements

Case statements - SQL Tutorial

From the course: SQL Server Fundamentals: Master Basic Query Techniques

Start my 1-month free trial

Case statements

- [Instructor] If this course were an album, I would call this last section, the bonus tracks. You could do a lot with just what we've gone over already but I want to give you a couple more tools to help you with data manipulation. There are times when you might want to present the data a little differently than it's available to you in your table, or you might want to show different texts depending on the data state. And that's where case statements can come in really handy. So on the screen here, we have a few things that we haven't covered yet. So first we've got this scalar variable, which we declare and then name with the @ symbol at the front. And then we told SQL server, what kind of data we're going to hold in this variable. And then this case we're using an int. And then we can assign a value to this variable using equals and we'll say five. So now, whenever we see at number in our code set, it will replace it with whatever value we've assigned here. So five. So next down…

Contents