Tag: SQL Server

How to Declare a variable in SQL Server ?

You will most likely declare a variable in the SQL Server and use it in the SQL Statements. You can use the DECLARE statement and specify the variable and datatype and optionally provide a default value. For example , You can declare an NewEmployeeJobTitle variable using the DECLARE statement and provide a default value as ‘Chief Executive Officer’ DECLARE @NewEmployeeJobTitle nvarchar(50) = ‘Chief Executive Officer’;…

Equivalent of IF Statement in SQL Server

There are times when you want to perform conditional checks within a SQL Query in SQL Server . Below is a sample Query that demonstrates how to do it. Equivalent of IF Statement in SQL Server Assume that the Employee table contains a column called “Designation” and we might want to show a value 1 if the designation is SSE else show 0 . You…

How to Check if a login exists in SQL Server ?

If you need to check if a login exists in SQL Server , you can use query the master.dbo.syslogins for it. How to Check if a login exists in SQL Server ? Here’s a sample query demonstrating how you can query master.dbo.syslogins to find out if the login exists in SQL Server. This would retreive all the details of the loginid ‘sa’.

How to copy tables from a database to another in SQL Server ?

There are times when you may want to copy the tables from one database to another along with the data or import data along with the schema in SQL Server. One of the ways to do this is using the SQL Server Import/Export Wizard. How to copy tables from a database to another in SQL Server ? 1. Launch SQL Server Import and export wizard…

Using BETWEEN clause to specify range of values in SQL Query

In SQL Server 2014 , you can use the BETWEEN clause to specify a range of values in the search criteria. How to specify a range of values in a Query in SQL Server ? For example , you want to to query the Employee table to display the employees having the birthdate between 1969-01-29 and 1975-12-01′ , you can use the BETWEEN clause as…

Connecting to a Database in SQL Server Management Studio

Most of the time you will be connecting to your database when working in SQL Server Management Studio. You want to know how to connect to a particular database in SQL Management Studio when working with SQL Server 2014 and executing a query. For example , you want to connect to the AdventureWorks2014 database. How to connect to a database in SQL Management Studio in…