sql server自定义函数
CREATE function [dbo].[f_testFunc]( @v_id nvarchar(4000) ,@v_type nvarchar(4000) ) returns NVARCHAR(4000) as begin declare @str_res NVARCHAR(4000); declare @str_id NVARCHAR(4000); declare @str_code NVARCHAR(4000); declare @str_name NVARCHAR(4000); SELECT @str_id = a.id,@str_code = a.event_code,@str_name = a.event_name FROM app_event a WHERE a.id = @v_id; IF(@v_type='id') RETURN @str_id IF(@v_type='code') RETURN @str_code IF(@v_type='name') RETURN @str_name return @str_name; end GO