存储过程只是节约大量SQL语句的传输时间.如果数据库和IIS是一台机器就无所谓

解决方案 »

  1.   


    CREATE procedure test
    (
      @str varchar(20)
    ) as
         @s int
          select @s=count(*) from table1 where fname=@str
         if @s>0
       begin
       .....
      end大概就这样,其中逻辑判断你就自己写吧
      

  2.   

    --因为不熟悉LZ数据库,所以拿Pubs数据库的两个表做了测试
    --在测试之前,把Job表的ID=14的列删除了,然后新建一个job_id=15的列
    select * from jobs
    select * from employeedeclare @max int,@i int,@id int
    set @i=1
    select @max=max(cou) from view_aaa
    while @i<=@max
    begin
    select @id=job_id from view_aaa where cou=@i
    print @id
    if exists(select * from employee where job_id=@id)
    begin
    print '有--'
    Set   @i=@i+1  
    continue  
    end
    print '没有'
    Set   @i=@i+1  
    end
    create view view_aaa
    as
    SELECT cou=COUNT(*), hyt.job_id, hyt.min_lvl
       FROM jobs AS hyt, jobs as czy
       WHERE hyt.job_id>= czy.job_id
       GROUP BY hyt.job_id, hyt.min_lvl
    GO
    测试结果--------------------希望对你有帮助
    job_id=1
    没有
    job_id=2
    有--
    job_id=3
    有--
    job_id=4
    有--
    job_id=5
    有--
    job_id=6
    有--
    job_id=7
    有--
    job_id=8
    有--
    job_id=9
    有--
    job_id=10
    有--
    job_id=11
    有--
    job_id=12
    有--
    job_id=13
    有--
    job_id=15
    没有
      

  3.   

    Create Proc mytest_Proc
    @str varchar(50)
    AS
    BEGINSET NOCOUNT ON
    DECLARE @sql varchar(8000)
    DECLARE @fcc varchar(100)set @sql=''if exists(select * from table2 where fname=@str)
    begin
    DECLARE c cursor fast_forward from select fcc from table2 where fname=@str
    open c 
    fetch next from c into @fcc
    while @fetch_status=0
    begin
    set @sql='select * from table1 where fname='+@str+' '
    set @sql=@sql+' and fcc='+@fcc+' 'if exists(exec(@sql))
    update table3 set fcount=fcount+1 where fcc=@str
    else
    insert into table3(fcc,fcount) values(@str,1); fetch next from c into @fcc
    end 
    close c
    deallocate c
    endEND
    GO仅供参考