Is it possible to catch the value of any field in a table? and once catched, can it be inserted into another table? SQL I'm trying to catch a field from a table (User), for example the Id, to be inserted in another table.

Example:

DECLARE @tempUSERNAME NVARCHAR(1000) = 'HERE USERNAME'
DECLARE @tempUSERID NVARCHAR(1000) = 'HERE USERID'

SELECT Id, UserName FROM Users WHERE UserName = @tempUSERNAME;
GO

INSERT INTO Person(Id, FirstName, LastName, UserId) VALUES
(newid(), 'FIRST NAME', 'LAST NAME', @tempUSERID);
GO


And the error that I have is:

Must declare the scalar variable "@tempUSERNAME".


But is it possible, or could I catch it with a subquery?
The GO utility statement marks the end of a batch of T-SQL statements.

The variables you declared at the top of the first batch go out of scope after the first GO statement.  So you can't use them anymore in the 2nd batch (where the INSERT statement is).

To solve that, just remove the GO statement.

As far as your other goal, you can store the Id that goes with that UserName by changing your SELECT statement to this:

SELECT @tempUSERID = Id
FROM Users 
WHERE UserName = @tempUSERNAME;


Notice the variable assignment in the SELECT clause.