Home Blog Page 3

Conditional evaluations in SELECT clause – Section6


In the previous article we discuss about pre-build function in sequels or as well as how we can be able to implement them in a select statement. In this movie we’ll discuss how to use a conditional evaluation in a select statement.There are two ways how we can be able to implement conditionally volition select statement the original way how we can be able to do that was using kids when a statement will do case when an evaluation of some sort.

Then what should be the result of that evaluation should it be. And we can repeat a when and then for different conditions. Finally we can put the else statement what should happen if any of the previous conditions are not being met. In a recent version of sequencer Microsoft added this I function. I have some condition this will be a true evaluation. Or what should happen if this is true. Else what should we display.


If this is wrong or false of secure this one one is greater than zero. Then this statement will be executed. Then we’ll see here a greater Also if we execute. This is the atom. I have zero craters on one. This is not true than these Vayu or a laser or be executed said use in a case where or if statement for a string or number literals like the one we did it before we can also be able to implement it in a select statement that is queering from a table or a data set.

For example we are tasked to categorize and c reate.You can create a column called economics that is based on a GDP that have greater than 300 billion to be locked and everything else to be called. Give a little peek. If we execute the sequence statement we’ll see. For Australia it has more than three hander which is four hundred seventeen billion GDP so that it’s categorized as developed here.

But if we look at Afghanistan here it only has 20 billion of GDP so that it was categorized as terrible pink. We can also be able to add additional conditions here. For example if we first categorize this one case when GDP greater than 300 to be called developed in any country that has between 200 and 300 to be called Dave or pink and everything else to be underdeveloped now free execute the select statement again we’ll see Australia being developed.

We haven’t changed any condition on that one. Afghanistan will see under a lot of our GDP is not between a hundred and 300. And you might see other countries like here that’s going to say that the lopin its annual GDP is two hundred forty three billion dollars.


How to change column headings and perform mathematical operations in SELECT? Section5

How to change column headings and perform mathematical operations in SELECT?

In the previous article we’ve seen how we can be able to project or display all these columns from a table as well as how we can be able to display only the top end rolls from a table in this movie you will see how we can be able to change a column hitting inside a select statement and how we can be able to perform some mathematical operation using columns is a select state.

I will also give you some overview of what mathematical operations or functions looks like inside a select statement. In this example some experts predicted that a population of every country in the world will be increasing by a million people in the next five years. And you are asked to call it final. Population value. Thirty five years. In this case what you can do is you can use a select statement a name of a country and our population size plus one million from country.

If you execute the sequence statement without using a column heading you’ll get a name like Australia Afghanistan and other countries. But for the newly created you not have any money in order to give it a column heading for I knew would call quited Cole and you can do as an economy now if execute the sequence statement. It’s going to give me a name of a country as well as the projected population besides using some simple mathematical operation like this.

Once the calls are also has some pre-built functions like this for example. In this case we want to calculate the total area in a row of every lake in the world that we can execute this one. This is going to be our total area in an average area of every link in the world. SQL Server also follows a mathematical rule or Mars or Rockett older division multiplication by addition and subtraction.

Like for example in this case we have two plus three times for the result. Could it be two plus 3 which is 5 5 times 4 which is 20. But because of bored us sequel server won’t finish multiplication ahead of time then it’s going to be three times four. Which is 12 plus 2. It is 14. So if we execute this month then we’ll get 14. But if we want to change how this operation works and we want to add two and three fourths then multiply it by 4.

We can use a bracket since the bracket comes first. The important rule then this will be calculated ahead of time. Then the result will be multiplied by four. Two plus three will be five lifetimes or is going to be 22. Now if I execute this statement I’ll get twenty.

How/ Why comments in SQL? Section3


In a previous article we’ve seen how we can be able to create the data is using a sequence script as well as a Server Management Studio features. We’ve also created in set up our sample data. We’ve also seen how we can be able to leverage drag control functionality in SSME so that we can be able to expedite it.

RC called development process we’ve seen how we can be able to select the top 1000 from any table. In it means without having to write any query so that we can be able to see what’s the structure of that table. If we are not familiar with that database we’ve seen how we can be able to change data in this context in a multi data environment.

This will be rather is going to be a very short one. We’ll see why we need comments as well as how we can be able to write comments and comments are a text input which are normally ignored or that are not going to be interpreted by sequencer but comments will play a major role in providing additional information about Sikorsky that we are creating.

Especially in a big database project that involves multiple developers. Sokolski it’s usually you’ll have who the author of that script is. What’s the purpose of the story. And then if there is any additional comments. And when was this screwed you did. Who created it. And if there are going to be multiple revisions to that original script we’re going to be adding the date of the revision. Who is the person who revised it. Why was there a change from the initial version. We need to specify that we also need to specify a usage of the script itself.

How is it going to be executed is it going to be executed from some windows job or is services going to call it or an API is going to call all sorts of procedures all that has to be specified so that the next person who will pick up are called to continue to evolve that will have a warning for Mission y. The script was read in what the purpose of that script is and how it’s going to be used. There are two forms sort of comments in sequence.

One is a multi-line com which is a C style comment. This is a novel he meant I am ready if I continue Adim additional lines. All of them is going to be commented out and till I add my closing syntax which is astri’s plus slush the other form of commenting is using double dashes for a single line. This is all in common. If I can teach me to try ears you’re not going to be combing.

But if I want to comment this want I can always go ahead and comment each line. Or we have additional feature in management studio we can uncomment these single line comments at once or we can comment them like this or we can do it control key control you to uncomment all control key.

Control-C to comment multiple lines together at the same time. This is what comments looks like in the course of Azi in the next article.


What an SSMS environment looks like? Important Short cuts -Section2


After a successful installation of SQL Server you can operate by going to the taskbar and types SQL Server Management Studio Or you can simply type SSMS. It’s just a mess. You’ll see this I can click on it after SQL Server Management Studio opens you’ll be mate with the connection dialog box.

If you accidentally cancel that one, you can always click there and you get this connection box. To connect to the server that you’re working on Give it the server name or your machine name. Or the simplest way to get your current machine name is just typed localhost then press connect. After you connect to the server using a server name which is localhost or an alias for our server name right here you’ll see databases Right now we don’t have any database that is created.

You might see some system diseases like master,model, msdb, tempdb monster is basically where you server holds all the important information and like the logging model is basically it will hold some template data for SQL Server uses to create some objects and msdb has something to do with SQL Server Agent or to run a scheduled jobs. TempDB is where it’s holding a temporary data or temporary tables. Don’t change anything here don’t delete any one of them so it might crash the entire sequence so.

Next you’ll see a security folder here under it. You’ll see logging, server role, credential, audit and audit specification. You don’t need to change anything here. But for us, since we created the server which makes it more let’s create one secure user account Right-Click new logging logging name. You can say See call user.  So it’s going to be a sequel authentication mode. Give it a good password here and repeat the same password here.

And you can choose a default database. Right now since we don’t have any user data mean leave the default answer on and enforce or pass on security. This is just temporary. So don’t enforce anything here and check that out. OK.

That will create a new user name sequel user. So if you want to log into the server using data logging You can always disconnect by clicking this button and click on to reconnect to change the authentication for windows to see quiet indication the server name is the scene local localhost top you know your user name which is call underscore a user for logging.  It’s not the case the but for a password. You have to provide it with the correct case. You can click to remember it but if it’s machine that is used by multiple people don’t click. Remember click connect.

Now as you can see going up to localhost using our new account which is Seacole user you’ll see some server objects here. Here is where we do a backup endpoint a link server link server if you have multiple servers and if you want to use a data that is stored in a sequel server that resides on a different Windows machine you can create a link server across a network. Replication is where you create your disaster recovery and then high availability. For now this is not the D.V. cause Don’t worry about this one.

Poley this is basically a new addition to see where you can access data that resides on and non-sequel or something like Hadoop. Always want to have availability is something sequencer added in a recent versions where you can create a deep grooves so that you can increase the performance of food and as well as make sure there’s no loss of data.

Management is another one you can create some policies extended even so you can create some extended events to see what’s going on inside the server. If theories deadlocks or anything like that here’s where you get a sequence of looks. If there is any error on the server or data level I’m getting an error because the sequel user doesn’t  have a mission to see that one. You can go back to our windows account restrictive account and be able to see that in detail. And we have integration services catalog.


If you install the course of integration services or is this is where you deploy your hardware and we have sequencer agent job if you want to execute some sort of procedure. For example if you want to send some e-mail to your users you can run us through procedure in UK in bulk data e-mail you can automatically send to them or you hear integration jobs needs to be executed. Here’s where you will see conserver agent and you can execute this job based on some schedule or based on some interval at the top you’ll see you know that you know file Nien Open Save save or everything is there.

It is the scene and do copy paste all they are is there server or object Explorer if you want. Well for example if you lost your object Explorer you can always go to View and click on object Explorer is that you can recover this back or you can open other other objects like the toolbox. We have a debug here if you have some still of procedures that you need to step in as they are. And if you want to depart them thoroughly you’ll use this functionality here we have a toolbox here. This is where you change your options for example to create creating new Querrey here as you can see here there’s no line number if you want to line number so that you can be able to reverse that.

You can go to Tools Options text editor you can go to transact see if you click on line number and click ok. You’ll see line 1. So wait so it’s good to keep adding line numbers for you here. The window is if you have multiple windows you can switch from one to the other or you can split this working window. And hell is basically it’s an on line here.

That’s what the sequencer meaning is looks like. Here we have new window. If you want to write a new sequence so you can click on that one go in and type your queries or select will use your insert wherever see where you have to go here and you have all this say and open here and open you’ll do the same. And if you can do for example new we have control and you can compress control and an end or it’s going to create a new query window or you can do control all it’s going to open.

These once the MDX and in Italy these are basically used in the sequence of analysis services. We know it’s going to be working on that one. If you have a multi pull databases and if you want to switch between one to the right now the current data is that we are working on is a master.  If you want to switch to model you can change is you have a user get visas if you want to switch from one day to every city out there or you can use are reserved for use and that will switch the context of that.

That means that you’re working on if you want to execute the call.  Here is where you execute it executes a month. For example select 1. And if I do execute, click on execute you’ll see there is no column name If I rename it as col_name now you will see this one will be changing to Col_name instead of no column name here. Or the simplest thing is we can do F5.  You can have multiple sequence statement in one query window.


For example, I can do select one column name. I can do select to call name in a file execute. You will see column one and of a cone column name too and you want to exit only a specific sequel’s statement.  You can’t always select that one and execute it.Now you’ll see number two and you don’t see number 1. So if you want to execute only a specific part of your query you have to select that part in executive or press F5 that will execute it for you. Debug we discussed about it when we talk about the debug menu this is what the SQL Server environment looks like.

And we’ve also discuss what are some of the shortcuts that you can use to automate your SQL development process. I see in the next article.