I have the following SQL:
DECLARE @HospitalReport TABLE (Registrator VARCHAR (20))
INSERT INTO @HospitalReport (Registrator)
VALUES("64")
SELECT
@HospitalReport.Registrator
FROM
@HospitalReport
IF Registrator > 0
BEGIN
SELECT
Database.dbo.Users.Firstname, Database.dbo.Users.Lastname
FROM
StradaAnv.dbo.Anvandare
WHERE
Id = Registrator
IF Firstname != NULL AND Lastname != NULL
BEGIN
UPDATE @HospitalReport
SET Registrator = Firstname + ' ' + Lastname
WHERE Registrator = Registrator
END
END
SELECT * FROM @HospitalReport
When I run this code, I get the following error:
Msg 137, Level 16, State 1, Line 9
Must declare the scalar variable "@HospitalReport"
What I see, I already have declared @HospitalReport
as a table?
NULL
with the standard equality and non-equality operators - you must useFirstName IS NULL
(orIS NOT NULL
) – marc_s