How to fix “Must declare the scalar variable” error when referencing table variable?

This is a long standing parser issue. You need to get rid of the table prefix or wrap it in square brackets.

i.e.

delete from @CompanyGroupSites_Master 
where CompanyGroupID = @CompanyGroupID

or

delete from @CompanyGroupSites_Master 
where [@CompanyGroupSites_Master].CompanyGroupID = @CompanyGroupID

Not

delete from @CompanyGroupSites_Master 
where @CompanyGroupSites_Master.CompanyGroupID = @CompanyGroupID

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)