Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
)
question from:https://stackoverflow.com/questions/4647700/sql-stored-procedure-set-variables-using-select

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
152 views
Welcome To Ask or Share your Answers For Others

1 Answer

select @currentTerm = CurrentTerm, @termID = TermID, @endDate = EndDate
    from table1
    where IsCurrent = 1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...