create procedure prco_data
@id int
as
select 名字,等级 
from tb
where id=@id

解决方案 »

  1.   


    --可以用函数:
    create function f_Get_Name(@id int)
    returns varchar(100)
    as
    begin
      declare @username varchar(100)
      select @username=username from tb where id=@id
      return @username
    endselect dbo.f_Get_Name(1)
      

  2.   


    --将名字、等级合并后取的
    --若是想根据字段名称动态取到,则要用stored procedure.
    CREATE FUNCTION getDataByID(
        @ID INT
    )
    RETURNS VARCHAR(100)
    AS
    BEGIN
        DECLARE @Ret VARCHAR(100)
        SET @Ret=(SELECT Name+','+RTRIM(等级) FROM TableName WHERE ID=@ID)
        RETURN @Ret
    END
      

  3.   


    我需要返回一个数,就用通过一个id值返回name。应该用函数吧,这个函数语法是怎么样的?
      

  4.   


    create proc wsp
    @id int
    as
        select name from 表名 where id=@id
    go