取出表A中Id为两位数的记录 取出表A中Id为四位数且前两位跟传进来的参数一样的记录select * from A where len(id)=2 
select * from A where len(id)=4 and left(id,2)=参数 拜托各位再帮忙把上面的两条sql写成个存储过程 参数 是ID 
我的ID是01,0101,010101这样的分3级 
如果传进来的ID参数ID=01 就找到0101 如果是0101 就找到010101 拜托了 

解决方案 »

  1.   

    create proc p 
    @s int
    as 
    begin 
    select * from A where len(id)=2 
    union all
    select * from A where len(id)=4 and left(id,2)=@s 
    end
      

  2.   

    create proc proc_test
        @id varchar(20)
    as
        select * from [Table] where len(id)>len(@id) and left(id,2)=@id
      

  3.   

    create proc proc_getdata @id varchar(30)
    as
    begin
    select * from tb
    where len(id) = len(@id)+2 and left(id,len(@id))=@id end
      

  4.   

    create proc f
    (
      @id varchar(20)
    )
    as
        select * from [Table] where len(id)>len(@id) and left(id,2)=@id
      

  5.   

    首先要判断传进来的Id是几位数的 如果是2位数的 那就要取Id为4位数的记录 且最前面两位必须是跟传进来的Id相同
      

  6.   

    create proc proc_test
        @id varchar(20)
    as
        select * from [Table] where len(id) between len(@id) and len(@id)+3 and left(id,2)=@id
      

  7.   

    create proc sp_test @s int
    as 
    begin 
      select * from tb where len(id)=len(@s)+2 and left(id,len(@s))=@s 
    end
      

  8.   

    create proc p 
    @s int
    as 
    begin 
    select * from A where len(id)=len(@s)
    union all
    select * from A where len(id)=len(@s)+2 and left(id,2)=@s 
    end
      

  9.   


    CREATE PROC sp_test(@ID INT)
    AS
    BEGIN
      SET NOCOUNT ON
      SELECT * FROM A WHERE ID=@ID OR (LEN(ID)=4 AND LEFT(LTRIM(ID),2)=@ID) OR (LEN(ID)=6 AND LEFT(LTRIM(ID),2)=@ID)
      SET NOCOUNT OFF
    END