CREATE FUNCTION getChName (@FName varchar(20))
RETURNS nvarchar(20)
AS
BEGIN
DECLARE @Result nvarchar(20)
select @result=中文名 from B where 字段名=@FName
return @result
END
第二步,用execute得到結果:
execute ('select name as '+dbo.getChName('name')+',age as '+dbo.getChName('age')+',sex as '+dbo.getChName('sex')+' from A')