exec ('select @info from Table1 where ID='+@id+' and Name='+@name)

解决方案 »

  1.   

    To CrazyFor(Fan):
    你的写法提示“在函数内不正确地使用了'Execute'”!?
      

  2.   

    exec ('select @info=info from Table1 where ID='+@id+' and Name='+@name)
      

  3.   

    呵呵,不用上面select @info=info from Table1 where ID='+@id+' and Name='+@name
      

  4.   

    变量没有赋值当然不能输出了CREATE FUNCTION f_demo(@id int,@name nvarchar) 
    RETURNS varchar(1000)
    AS
    BEGIN
             declare @info nvarchar(1000)
    select @info=info from Table1 where ID=@id and Name=@name
    return @info
    END
    GO
      

  5.   

    To sky_blue(老衲) :
    你试试用这样的语句调用函数f_Demo:select Info=dbo.f_Demo(1,'David'),还是没有数据。
      

  6.   

    CREATE FUNCTION ToDate (@ReturnDate DateTime)
    RETURNS DateTime   
    BEGIN 
    DECLARE @NewDate DateTime
    Select @NewDate = CONVERT(DateTime, DATENAME(yyyy, @ReturnDate) + '-' + DATENAME(mm, @ReturnDate) + '-' + DATENAME(dd, @ReturnDate), 102)
    Return @NewDate
    END