Skip to main content

Posts

Showing posts with the label SQL Server BETWEEN operator

What is @@RowCount in SQL? What does this statement do @@RowCount?

The  @@ROWCOUNT  is a special variable of SQL. It will return the number of rows changed by the last statement. The @@RowCount is equal to (=) the number of rows changed by the last statement. Syntax : - @@ROWCOUNT Return Types : - INT What is the scope of @@RowCount? The @@RowCount is both the scope and connection safe and it is read only! For example as, -- DECLARE RETURN TABLE DECLARE @Return_Table TABLE (Code varchar ( 10 ) ,Message varchar ( 100 ), ID varchar ( 100 )) --UPDATE CUSTOMER QUERY UPDATE Customer SET Name = N 'Anil Singh' WHERE Id = 0786 --USE OF @@ROWCOUNT IF (@@ROWCOUNT > 0 ) BEGIN INSERT INTO @Return_Table (Code, Message, ID) SELECT 'OK' , 'SUCCESS' , SCOPE_IDENTITY() SELECT Code, Message, ID FROM @Return_Table END ELSE BEGIN INSERT INTO @Return_Table (Code, Message, ID) SELECT 'ERROR' , 'Warning - No rows updated.' , SCOPE_IDENTITY() SELECT Code, Message, ID FROM @R...

SQL Server BETWEEN operator

The BETWEEN operator is used to select the values within a range. Syntax: -- Used of BETWEEN SELECT col1, col1 FROM Table_name WHERE col1 BETWEEN val1 AND val2; -- 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], [IsActive], [IsDeleted]) VALUES ( 1 , N 'Anil Singh' , 30 , 1 , 0 ) GO INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsActive], [IsDeleted]) VALUES ( 2 , N 'Aradhya' , 3 , 1 , 0 ) GO INSERT [dbo].[Tbl_Demo] ([ID], [N...