Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Expert I need to Select From the First Table called FIRST if it returns NIL

I need to do the Select from the SECOND Table.


Please Assist


The Selection Should be from Either FIRST or SECOND Table


Please Assist By completing the Stored Procedure Below


SQL
ALTER PROCEDURE [dbo].[sp_GetGridLnid]
(
   @BRNNO	varchar(20)output  ,
   @BEMPNO  varchar(50) output ,
   @BFNAME  varchar(50) output ,
   @BLNAME  varchar(50) output ,
   @RETURN  varchar(10) output  
  
  )

 AS
 Begin
	Begin
	     SELECT DISTINCT
	       @BRNNO         = IDNO  ,
	       @BFNAME        = FNAME ,  
	       @BLNAME        = LNAME  
	FROM FIRST WHERE IDNO=@BRNNO
		
	  SET RETURN='FIRST' 



              SELECT DISTINCT
	       @BRNNO         = IDNO  ,
	       @BFNAME        = FNAME ,  
	       @BLNAME        = LNAME  
	FROM SECOND WHERE IDNO=@BRNNO

               SET RETURN='SECOND' 
 	
	End
 End




Thanks

What I have tried:

This is a program codes which I have done
Posted
Updated 8-Sep-19 9:08am
v2

1 solution

You can use IF EXISTS, see example here:
SQL Server IF EXISTS THEN 1 ELSE 2 - Stack Overflow[^]
 
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