ttmind

Main Content

Please wait...

Use of TOP and DISTINCT in SQL SERVER

TOP and DISTINCT clause. TOP applies to: SQL Server (starting with 2008), Azure SQL Database, Azure SQL Data Warehouse and Parallel Data Warehouse DISTINT applies to: SQL Server Analysis Services TOP Clause: TOP is mainly used to limit the result of query in terms of number or percentage of the result from database. It selects result limits to TOP from N numbers of data from ordered rows by using ORDER BY statement otherwise it selects undefined order data. TOP can be used in statem ....Read More

SQL Server Stored Procedures: Part-5

SQL Server Dynamic SQL and SQL Injection SQL Server Stored Procedures: Part-4, Click here. Dynamic SQL is used to construct SQL statement dynamically at run time. In case you don’t know all the SQL statement at compilation time, dynamic SQL is effective. You can use dynamic SQL to create Stored Procedure to query data whose table name is unknown at compilation time. For Example: CREATE PROC uspEmployee( @tableName NVARCHAR(100), @topN INT, @Column NVARCHAR(100) ) ....Read More

SQL Server Stored Procedures: Part-4

SQL Server TRY CATCH For SQL Server Stored Procedures: Part-3, Click here. TRY CATCH Statement SQL Server TRY CATCH construct is used to handle error in stored procedure. Syntax: BEGIN TRY --Statements that may cause exceptions END TRY BEGIN CATCH --Statements that handle exceptions END CATCH If TRY block executes without any error then CATCH block does not executes. But if TRY block executes with error then control transfers to the statements in CATCH block. Functions of CATCH ....Read More

SQL Server Stored Procedures: Part-3

SQL Server CURSOR For SQL Server Stored Procedures: Part-2, Click here. Database cursor act like a pointer in a database. It process query on each row one by one. Cursor act like a pair of tweezers to pick up each row of data from bag of data. You should use cursor if you have large amount of data and need to act individually on each row. Cursor doesn’t need to allocate big chunk of space in server to load result set like in SQL. Life cycle of SQL Server cursor: Step for using a cu ....Read More

SQL Server Stored Procedures: Part-2

Control-of-flow statements: For SQL Server Stored Procedures: Part-1, Click here. BEGIN….END Statement: The BEGIN….END statement contains set of SQL statement and executes block of SQL statement. Syntax: BEGIN { SQL Statement || Statement Block} END For example: BEGIN SELECT First_Name, Salary FROM dbo.EmployeeDb WHERE Salary> 100000; IF @@ROWCOUNT= 0 PRINT 'No one has greater than 100000'; END Syntax D ....Read More

SQL Server Stored Procedures: Part-1

If you don't have database, you can find it here. Creating Stored Procedure: CREATE PROCEDURE or CREATE PROC query is used to create stored procedure: CREATE PROCEDURE uspEmployeeList AS BEGIN SELECT Emp_ID, First_Name, Last_Name FROM dbo.EmployeeDb ORDER BY Emp_ID END Syntax Description: uspEmployeeList is the name of the stored procedure. AS keyword seperates the head and body of stored procedure. BEGIN and END keywords surrounding statement are optio ....Read More
Bulk Import of Data (SQL Server) Data file for Demonestration of Stored Procedure is in this link GitHub. Step 1: Create Database Step 2: Right click to database created, go to task and to Import Flat File. Step 3: Click Next Step 4: Browse the file, give the table name or keep it default and Click next. Step 5: Preview the data if all you want is correct or not and click next to change table data columns, data type etc. Step 6: Modify columns. Step 7: Click Finish and see summ ....Read More
1. nchar[(n)] (national character) i. Fixed-length Unicode string data. ii. n defines the string length and must be a value from 1 through 4,000. iii. The storage size is two times n bytes. 2. char [(n)] (character) i. Non-Unicode string data with fixed-length. ii. n defines the string length and must be a value from 1 through 8,000. iii. Storage size is n bytes. 3. varchar [(n | max)] (character varying) i. Variable-length, non-Unicode string data. ....Read More

What's new in SQL Server 2019?

Microsoft announced the latest preview of SQL Server 2019 on this September and Celebrating 25 years of SQL Server Database Engine since SQL Server first shipped on Windows NT in 1993. In every release of SQL server, Microsoft makes inner optimizations that enhance performance. In this release there is no License or support it only available for experiments. SQL Server 2019 makes a brought together information stage with Apache SparkTM and Hadoop Dispersed Record Framework (HDFS) bundled toge ....Read More

TRIM Function in SQL Server 2017

we can see that most of the languages have the trim function. But, Today I am going to write about Trim Function in SQL Server 2017. Trim Function helps to remove White spaces or other specified characters from the start as well as the end of the String. Syntax: TRIM ( [ characters FROM ] string )  Where Characters represents variable, literals or function call of any non-LOB character types (nvarchar, varchar, nchar, or char). But Data type like. varchar(max) and nvarchar(max) are not all ....Read More