I have a stored procedure in SQL Server 2005 with multiple variables and I want to set the values of these variables using a select statement. All three variables come from a same table and there should be a way to set them using one select statement instead of the way I currently have as shown below. Please help me to figure it out.
DECLARE @currentTerm nvarchar(max) DECLARE @termID int DECLARE @endDate datetime SET @currentTerm = ( Select CurrentTerm from table1 where IsCurrent = 1 ) SET @termID = ( Select TermID from table1 where IsCurrent = 1 ) SET @endDate = ( Select EndDate from table1 where IsCurrent = 1 )
select @currentTerm = CurrentTerm, @termID = TermID, @endDate = EndDate from table1 where IsCurrent = 1
1.4m articles
1.4m replys
5 comments
57.0k users