I'm a C# developer trying to become more familiar with SQL Server stored procedures.
I'm a little confused as to why the syntax in "A" works and "B" does not work with Set @id. What is happening here that makes "B" require Select instead of Set?
Example A (works)
DECLARE @currDateTime DateTime
SET @currDateTime = GetDate()
SELECT @currDateTime
Example B (does not work)
DECLARE @id int
SET @id = ID FROM [MyTable] WHERE [Field1] = 'Test'
Example C (works)
DECLARE @id int
SELECT @id = ID
FROM [MyTable]
WHERE [Field1] = 'Test'
FROMis belong toSELECTnot toSET. For more information look at this link