Category Archive: Sql Server

Feb 22

How to convert mm-dd-yyyy to mm-yyyy in sql server

Hi,In this article I will going to explain you how to convert ‘MM-DD-yyyy’ to ‘MMM-yyyy’ Every developer will face problem while converting date-time, I am keeping query to convert Datetime Eg:  (’12/01/2013 AM 12:00:00′)  to (‘Dec – 2013′) Query: [code language=”sql”] SELECT LEFT(DATENAME(MONTH ,CONVERT(VARCHAR(10), ’12/01/2013 AM 12:00:00′,112)),3) +’ – ‘+ DATENAME(YEAR,CONVERT(VARCHAR(10), ’12/01/2013 AM 12:00:00’, 112)) …

Continue reading »

Oct 27

how to alter a column data type which is a primary key in the table

Hi, In this article I will explain you how to alter a column data type which is a primary key in the table –>We can’t alter the primary key column data type directly by using query –>To do that we have to delete the primary key first and then we have to alter the column …

Continue reading »

Oct 25

how to get second highest salary in sql

Hi, In this article I will explain you a common interview question Question : How you will get second highest salary from  Employee table Ans:  Just simply Explain this below query and Scenario Below Image shows you Employee table data Execute below query: [code language=”sql”] SELECT MAX(EmployeeSalary) AS SecondHighestSalary FROM Tbl_Mst_Employee WHERE  EmployeeSalary < (SELECT …

Continue reading »

Aug 21

how to copy data from one table to another table in sql server

Hi,In this artical i am going to explain about how to copy data from one table to another table in sqlserver –>In some cases its necessary to take the backup of your table data while Performing operations like Update,Delete,Insert . Especially,  when we are working with Live data –>To do that we can also create …

Continue reading »

Jul 15

How to change Edit/Select top 200/1000 rows to Edit/select all rows in sqlserver2008

In SQL Server 2008, selecting and editing records are 1000 and 200 respectively. Its very Difficult to edit the rows which are above 200 and also time consuming process. To get all the records for selecting and editing we can change as sqlserver2005 menu as below : 1- Open SQL Server 2008 Management Studio 2- …

Continue reading »

Jul 15

How to get entire information about sqlserver database

In this artical i am going to explain about,how to get entire information about Tables,StoredProcedure and views.   –>To get entire information about database select * from sys.objects –>To get Total count of StoredProcedures select Count(*) from sys.procedures –>To get Total count of Tables select Count(*) from sys.tables –>To get Total count of views select …

Continue reading »

Apr 09

Saving changes is not permitted in SQL Server

SQL Server Management Studio does not allow you to save changes to a table which require table re-creation such as changing data type for a column. When you perform such changes you will run into following error message: Here, I have tried changing data type for First’Name’ column from NVARCHAR(50) to VARCHAR(50). Since this requires …

Continue reading »

Apr 09

how to find difference between two dates in sql server 2008

To find the difference between two dates in SQLSERVER 2008 we have to use DATEDIFF() function as below ex:- [code language=”sql”] DECLARE     @Today      DATETIME = GETDATE() DECLARE     @IDay       DATETIME = ‘2013-07-31 08:30:00’ SELECT DATEDIFF(DAY, @Today, @IDay),  ‘Days Left’ UNION ALL SELECT DATEDIFF(MONTH, @Today, @IDay), ‘Months Left’ UNION ALL SELECT DATEDIFF(YEAR, @Today, @IDay),  ‘Years Left’ UNION …

Continue reading »

Mar 08

how to find duplicate records in sql server table

To List Duplicate Rows and Values in SQL Server To simply find duplicate values in a table use the following query (replacing “[ColumnName]” and “[TableName]” with the actual values): [code language=”csharp”] SELECT [ColumnName], COUNT(*) AS [DupeCount] FROM [TableName] GROUP BY [ColumnName] HAVING COUNT(*) > 1 [/code] To find duplicate values and list the rows that …

Continue reading »

Mar 07

how to write select update insert and select delete stored statements in sql server

In this article i am going to explain how to create stored procedures and how to call stored procedures. 1.Creating a stored procedures to insert,update and delete data into database tables 1.1.Open Sql server management studio 1.2.Select database 1.3 .Select New query window and run the below procedures 2.Creating Stored procedure to insert [code language=”csharp”] …

Continue reading »

Older posts «