I'm sure this is easy but I'm still getting syntax errors when I run it in SQL Server Management Studio v17.4.
I have table T1 which has serial numbers, and I just need to iterate through and check how many times they appear in T2. I tried like
declare @serial int
select @serial = select serial from T1
while @serial
begin
select count(*) from T2 where Serial = @serial
end
But I get an error:
Incorrect syntax near the keyword 'select'
How to do it? Thanks.
SELECT COUNT(*) FROM T2 WHERE Serial = @Serial?