I am trying somw thing like inside a stored proc. But, I am getting error like incorrect
syntax near select statement.
declare @var int
@var=select max(id) from table1 where sname=@'XXX'
You are missing the SET keyword, and have an extra @ you dont need. Additionally, I have wrapped the Select command in brackets.
DECLARE @var int SET @var=(SELECT max(id) FROM table1 WHERE sname='XXX')