Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone,
My name is Akashkumar, i need to know what is the meaning or use of "select -1" and why do we need this line or query?

this is where i have found it.

SQL
USE [TISDB]
GO
/****** Object:  StoredProcedure [dbo].[usp_SubContractor_insert]    Script Date: 08/21/2013 12:42:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


--Exec usp_SubContractor_insert 0,'Madhavi12-2-2010','3-3-2010','new Client','New Address',
--'New WorkName','New Work Order','New Work Order No','New Service Tax No','New Vat No','New Estimate Time'
--,1,1,1

ALTER procedure [dbo].[usp_SubContractor_insert] 
(
@SCCode int,
@SCCodeNumber varchar(50),
@SCName varchar(50),
@Sc_StartingDate varchar(11),
@Sc_EndingDate varchar(11),
@Sc_Address varchar(500),
@Sc_WorkName varchar(200),
@Sc_WorkOrderNo varchar(200),
@Sc_Stno varchar(50),
@Sc_vatno varchar(50),
@Sc_Estimatetime varchar(50),
@Sc_EstimateAmount varchar(50),
@Pancardno varchar(50),
@mono numeric(18,0),
@userid varchar(10),
@Tendercode int,
@LocationID varchar(10),
@Sync_Status bit,
@Layer varchar(10)
)
As
if @SCCode=0
begin
	if not exists (select * from SubCont_Master where SCCode=@SCCode And SCCodeNumber=@SCCodeNumber And SCName=@SCName) 
	begin
		select @SCCode=isnull(max(SCCode),0)+1 from [SubCont_Master]
		INSERT INTO [SubCont_Master] ([SCCode],[SCCodeNumber],[SCName],[Sc_StartingDate], [Sc_EndingDate],[Sc_Address], [Sc_WorkName], [Sc_WorkOrderNo], [Sc_STno], [Sc_VatNo], [Sc_Estimatetime], [Sc_EstimateAmount],[pancardno],[mono] ,[UserId],[Tendercode],[LocationID] ,[Sync_Status],[Layer],[Dt]) VALUES (@SCCode,@SCCodeNumber, @SCName,@Sc_StartingDate, @Sc_EndingDate,@Sc_Address, @Sc_WorkName, @Sc_WorkOrderNo, @Sc_STno, @Sc_VatNo, @Sc_Estimatetime, @Sc_EstimateAmount,@pancardno,@mono,@UserId,@Tendercode, @LocationID,@Sync_Status,@Layer,GETDATE())
		select @SCCode
	end
	else
	begin
		select -1
	end
end
else
begin
	if not exists (select * from SubCont_Master where SCName =@SCName And SCCodeNumber=@SCCodeNumber And Tendercode = @Tendercode and SCcode<>@SCCode)
	begin
		Update SubCont_Master Set [SCCodeNumber]=@SCCodeNumber,
		[SCName] = @SCName,
		[Sc_StartingDate] = @Sc_StartingDate,
		[Sc_EndingDate]=@Sc_EndingDate,
		[Sc_Address] =@Sc_Address,
		[Sc_WorkName]=@Sc_WorkName,
		[Sc_WorkOrderNo]=@Sc_WorkOrderNo,
		[Sc_Stno]=@Sc_Stno,
		[Sc_vatno]=@Sc_vatno,
		[Sc_Estimatetime]=@Sc_Estimatetime,
		[Sc_EstimateAmount]=@Sc_EstimateAmount,
        [pancardno]=@pancardno,
        [mono]=@mono,
		[UserId]=@UserId,
		[Tendercode]=@Tendercode,
		[LocationID] =@LocationID,
		[Sync_Status] =@Sync_Status,
		[Layer] =@Layer,		
		[Dt]=GetDate() where SCCode=@SCCode
		select @SCCode
			end
			else
			begin
				select -1
			end
		end

Thank you.
Posted
Updated 20-Aug-13 21:28pm
v3
Comments
Maciej Los 21-Aug-13 2:37am    
We can't help you without proper description of problem...
Akashkumar Bammrotwar 21-Aug-13 3:23am    
this is where i have found it.

USE [TISDB]
GO
/****** Object: StoredProcedure [dbo].[usp_SubContractor_insert] Script Date: 08/21/2013 12:42:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


--Exec usp_SubContractor_insert 0,'Madhavi12-2-2010','3-3-2010','new Client','New Address',
--'New WorkName','New Work Order','New Work Order No','New Service Tax No','New Vat No','New Estimate Time'
--,1,1,1

ALTER procedure [dbo].[usp_SubContractor_insert]
(
@SCCode int,
@SCCodeNumber varchar(50),
@SCName varchar(50),
@Sc_StartingDate varchar(11),
@Sc_EndingDate varchar(11),
@Sc_Address varchar(500),
@Sc_WorkName varchar(200),
@Sc_WorkOrderNo varchar(200),
@Sc_Stno varchar(50),
@Sc_vatno varchar(50),
@Sc_Estimatetime varchar(50),
@Sc_EstimateAmount varchar(50),
@Pancardno varchar(50),
@mono numeric(18,0),
@userid varchar(10),
@Tendercode int,
@LocationID varchar(10),
@Sync_Status bit,
@Layer varchar(10)
)
As
if @SCCode=0
begin
if not exists (select * from SubCont_Master where SCCode=@SCCode And SCCodeNumber=@SCCodeNumber And SCName=@SCName)
begin
select @SCCode=isnull(max(SCCode),0)+1 from [SubCont_Master]
INSERT INTO [SubCont_Master] ([SCCode],[SCCodeNumber],[SCName],[Sc_StartingDate], [Sc_EndingDate],[Sc_Address], [Sc_WorkName], [Sc_WorkOrderNo], [Sc_STno], [Sc_VatNo], [Sc_Estimatetime], [Sc_EstimateAmount],[pancardno],[mono] ,[UserId],[Tendercode],[LocationID] ,[Sync_Status],[Layer],[Dt]) VALUES (@SCCode,@SCCodeNumber, @SCName,@Sc_StartingDate, @Sc_EndingDate,@Sc_Address, @Sc_WorkName, @Sc_WorkOrderNo, @Sc_STno, @Sc_VatNo, @Sc_Estimatetime, @Sc_EstimateAmount,@pancardno,@mono,@UserId,@Tendercode, @LocationID,@Sync_Status,@Layer,GETDATE())
select @SCCode
end
else
begin
select -1
end
end
else
begin
if not exists (select * from SubCont_Master where SCName =@SCName And SCCodeNumber=@SCCodeNumber And Tendercode = @Tendercode and SCcode<>@SCCode)
begin
Update SubCont_Master Set [SCCodeNumber]=@SCCodeNumber,
[SCName] = @SCName,
[Sc_StartingDate] = @Sc_StartingDate,
[Sc_EndingDate]=@Sc_EndingDate,
[Sc_Address] =@Sc_Address,
[Sc_WorkName]=@Sc_WorkName,
[Sc_WorkOrderNo]=@Sc_WorkOrderNo,
[Sc_Stno]=@Sc_Stno,
[Sc_vatno]=@Sc_vatno,
[Sc_Estimatetime]=@Sc_Estimatetime,
[Sc_EstimateAmount]=@Sc_EstimateAmount,
[pancardno]=@pancardno,
[mono]=@mono,
[UserId]=@UserId,
[Tendercode]=@Tendercode,
[LocationID] =@LocationID,
[Sync_Status] =@Sync_Status,
[Layer] =@Layer,
[Dt]=GetDate() where SCCode=@SCCode
select @SCCode
end
else
begin
select -1
end
end
Maciej Los 21-Aug-13 3:27am    
Use "Improve question" widget instead posting code in comment.
Thanks7872 21-Aug-13 2:38am    
There is nothing like select -1 in SQL Server. If you are confused about some thing you can elaborate your question.
Thanks7872 21-Aug-13 3:27am    
Just just remove all this code dump if you really want a solution. No one would like to go through all this. Just post the line which you want to be clear. Update question and notify the one about updation you made in question.

If your code contains the line
SQL
SELECT -1

Then almost certainly it's a "placeholder" line there just to return a value from a query or SP in the case of a problem.
All it does is literally select the value "-1" and return it as the query result, as if it had been the one and only column in the only row matching a WHERE clause.
 
Share this answer
 
Comments
Joezer BH 21-Aug-13 3:45am    
Probably true - 5ed!
yeah i am agree with OriginalGriff
its only to return something as result if there is no data found/manipulate or all data exists in your case.

the place from where this procedure is calling i think there will be some use of this -1 to validate something or some information page like no result found or something else.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900