我选择哪个工作得很好(它选择所有来自城市的学生'考纳斯'):
SELECT * FROM myserver.dbo.student
WHERE student.cityid =
(SELECT [id] FROM [LinkedServer].[Database].[dbo].[city]
WHERE [name]='Kaunas')
现在我尝试制作一个存储过程,可以将城市作为参数,并选择来自城市的学生。
CREATE PROCEDURE StudentByCity
-- parameters
@CityName varchar = 'Kaunas'
AS
BEGIN
SET NOCOUNT ON;
SELECT * FROM myserver.dbo.student
WHERE student.cityid =
(SELECT [id] FROM [LinkedServer].[Database].[dbo].[city]
WHERE [name]=@CityName)
END
GO
但是执行程序会给我返回空选。
答案 0 :(得分:3)
@CityName varchar = 'Kaunas'
您是否缺少参数@CityName varchar size?尝试
@CityName varchar(25) = 'Kaunas'