Why always said "@ vlastname and @ vfirstname" did not declare it? ?

Category: MS-SQL Server -> Foundation Classes Author: wt2066 Date: 2008-10-09 13:20:34
 
wt2066
2008-10-09 13:20:34
declare @ vlastname char (20),
@ vfirstname varchar (11)
set @ vlastname = 'Dodsworth'
select @ vfirstname = firstname
; from employees
where lastname = @ vlastname
print @ vfirstname + '' + @ vlastname
go

Will the program there anything wrong? ?
minwei_000
2008-10-09 13:33:14
After testing, the program's right, do not print the front part of the first run, and then run the print statement. To run with the entire contents.
use Northwind
declare @ vlastname char (20),
@ vfirstname varchar (11)
set @ vlastname = 'Dodsworth'
select @ vfirstname = firstname from employees where lastname = @ vlastname
print @ vfirstname + '' + @ vlastname
go
frisily
2008-10-09 13:45:57

you is not go back there in the script.

If yes, please go to remove.

because the go is a batch execution.

previously defined variables can not go behind the statement used
vincent53
2008-10-09 13:59:21
you tried, no problem /
l548871080
2008-10-09 14:14:14
Upstairs maybe find a key to the problem.