First Time Poster! :D
I have been searching for an answer to this everywhere, and as simple as I would think it should be, I can't find a straight answer anywhere. I am trying to create a stored procedure that will store multiple, potentially hundreds of select statements... Only one of which will actually end up running... after the @Look parameter is given (i.e. the table name). However, I keep receiving this error:
"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."
The error is pointing to the Else If and Else statements. How do I introduce exists to these statements? I've tried adjusting them to no avail.
Here is my script from a sample database:
Create Procedure [dbo].[sp_Look] ( @Look varchar (50) ) AS
Declare @Lookup varchar (500)
If (@Look = 'Employee_Information')
SET @Lookup =
( Select EmployeeId, EmployeeSSN, EmployeeStatus
From Employee_Information )
Else If (@Look = 'Employee_Demographic')
SET @Lookup =
( Select LastName, FirstName, DateOfBirth From Employee_Demographic )
Else SET @Lookup = 'No Table'
Select @Lookup
Aucun commentaire:
Enregistrer un commentaire