Skip to main content

Posts

Showing posts with the label drop a Stored Procedure in SQL Server

SQL Server SELECT INTO Statement [How To]

What is SQL “ SELECT INTO ”? And when you Use “ SELECT INTO ” ? In this Article, I going to share the detail about SQL Server “ SELECT INTO ” Statement and detail as following as. SQL SELECT INTO is use to “ SELECT ” data from one table and “ INSERT ” into a new table and also creates a new table located in the default filegroup . It is copied all columns records with same data types also. It is only “ INSERT ” the values of existing tables “ INTO ” a new table. SQL SELECT INTO statement can also use to “ Copy ” data from more than one table into a new table that means you can use “ SQL JOINS ” to “ SELECT ” records from multiple tables and “ INSERT ” in a single table. SQL SELECT INTO statement can also use to CREATE a “new”, “empty” table using another table schema. You can just add a “ WHERE ” clause that is return no records (empty rows). Stayed Informed - Create Country Table & Insert 192 Countries Data! Note:-   The “ New Table...

T-SQL CASE Expressions

The CASE expressions compare an expression to a set of simple expressions to determine the result and CASE can be used in any statement that allows a valid expression. It is IF-THEN-ELSE statement. Syntax: For a simple CASE expression CASE COLL WHEN 1 THEN 'One' WHEN 2 THEN 'Two' WHEN 3 THEN 'Three' ELSE 'None' END AS COLL_Name -- CREATE TABLE CREATE TABLE [dbo].[Tbl_Demo]( [ID] [ int ] IDENTITY( 1 , 1 ) NOT NULL , [Name] [ varchar ]( 500 ) NULL , [Age] [ int ] NULL , [IsActive] [ bit ] NULL , [IsDeleted] [ bit ] NULL , CONSTRAINT [PK_Tbl_Demo] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO --INSERT TABLE ROWS SET IDENTITY_INSERT [dbo].[Tbl_Demo] ON GO INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsA...

DROP a Stored Procedure in SQL Server

-- ============================ -- DROP YOUR EXISTING PROCEDURE -- ============================ IF EXISTS ( SELECT * FROM DBO . SYSOBJECTs where id = OBJECT_ID ( N'[dbo].[sp_Get_XX]' ) AND OBJECTPROPERTY ( id , N'IsProcedure' ) = 1 )     DROP PROCEDURE [dbo] . [sp_Get_XX] GO                                        --OR IF OBJECT_ID ( '[dbo].[sp_Get_XX]' ) IS NOT NULL     DROP PROCEDURE [dbo] . [sp_Get_XX] GO                                       --OR IF EXISTS ( SELECT NAME FROM SYSOBJECTS WHERE NAME = '[dbo].[sp_Get_XX]' AND TYPE...