How to set variable from a SQL query?

前端 未结 9 1407
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 01:19

I\'m trying to set a variable from a SQL query:

declare @ModelID uniqueidentifer

Select @ModelID = select modelid from models
where areaid = \'South Coast\'         


        
9条回答
  •  孤城傲影
    2020-11-28 01:43

    Select @ModelID =m.modelid 
    From   MODELS m
    Where  m.areaid = 'South Coast'
    

    In this case if you have two or more results returned then your result is the last record. So be aware of this if you might have two more records returned as you might not see the expected result.

提交回复
热议问题