我先来一句:显示表A01的前10条记录!select top 10 * from a01

解决方案 »

  1.   

    找出表a1,a2相同的列名:
    select left(A.name, 20) col, left(C.name,20) type, A.length from
     syscolumns A left join sysobjects B 
     on A.id = B.id left join systypes C
     on A.xtype = C.xtype
     where B.name = 'a1' or B.name = 'a2'
    group by A.name, C.name, A.length
    having count(A.name) > 1
    go
      

  2.   

    模糊查询:查询表ZL中所有姓李的记录select * from zl WHERE xm LIKE '李%'
      

  3.   

    建立索引create index 索引名  on tablename (listname  )
      

  4.   

    三个表:
    1、学生表:STUDENT 
    学号  名字
    SID   SNAME
    1     WAN
    2      NAM
    3     DNA
    2、课程表: COURCE
    课号  名字
    CID   CNAME
    1      EN
    2      CN
    3      US
    3、成绩     SC
    学号   课程号    得分
    SID    CID       SCORE
    1       1         90
    1       2         67
    1       3         30
    2       3         46
    3       1         89SQL 语句(1):查询没有选择任何课程的学生姓名
    select sname from student where not exists(
    select * from cource where not exists(
    select * from sc where sc.sid=student.Sid
    and
    sc.cid=cource.cid))SQL 语句(2):查询选择所有课程的学生姓名
    SELECT S.SNAME
    FROM dbo.COURCE   C INNER JOIN
          dbo.SC   SC
                  ON C.CID = SC.CID 
                        INNER JOIN
          dbo.Student  S 
           
           ON SC.SID = S.SID
    group by s.sname
    having 
    count(SC.CID)=(select count(*) from cource )
      

  5.   

    接上:
    --求有参加过课程的人
    select sname from student where exists(
    select * from cource where exists(
    select * from sc where sc.sid=student.Sid and
     sc.cid=cource.cid))--求有 没有参加课程的人
    select sname from student where exists(
    select * from cource where not exists(
    select * from sc where sc.sid=student.Sid and
     sc.cid=cource.cid))--求有参加所有课程的人
    select sname from #student where not exists(
    select * from cource where not exists(
    select * from sc where sc.sid=student.Sid and
     sc.cid=cource.cid))
      

  6.   

    按笔画多少排序
    select * from test
    ORDER BY xm COLLATE Chinese_PRC_Stroke_CI_AS_KS
      

  7.   

    打印查询结果
    osql -S myHost -E -d myDatabase -Q "select ....你的语句" > lpt1:
      

  8.   

    小写金额转大写
    Create    Procedure    AtoC
        @ChangeMoney    Money    
    as
        Set Nocount ON
        Declare    @String1    char(20)
        Declare    @String2    char(30)
        Declare    @String4    Varchar(100)
        Declare @String3     Varchar(100)    --从原A值中取出的值
        Declare @i         int        --循环变量
        Declare @J         Int        --A的值乘以100的字符串长度
        Declare @Ch1         Varchar(100)    --数字的汉语读法
        Declare @Ch2         Varchar(100)    --数字位的汉字读法
        Declare @Zero         Int        --用来计算连续有几个零
        Declare    @ReturnValue    VarChar(100)    Select @ReturnValue = ''
        Select     @String1 = '零壹贰叁肆伍陆柒捌玖'
        Select    @String2 = '万仟佰拾亿仟佰拾万仟佰拾元角分'    Select @String4 = Cast(@ChangeMoney*100 as int)        select @J=len(cast((@ChangeMoney*100) as int))    Select @String2=Right(@String2,@J)    Select    @i = 1     while    @i<= @j Begin        Select @String3 = Substring(@String4,@i,1)        if @String3<>'0' Begin            Select     @Ch1 = Substring(@String1, Cast(@String3 as Int) + 1, 1)
                Select    @Ch2 = Substring(@String2, @i, 1)
                Select    @Zero = 0                    --表示本位不为零
            end
            else Begin
                If (@Zero = 0) Or (@i = @J - 9) Or (@i = @J - 5) Or (@i = @J - 1)
                            Select @Ch1 = '零' 
                        Else
                            Select @Ch1 = ''                    Select @Zero = @Zero + 1             --表示本位为0
                            
                --如果转换的数值需要扩大,那么需改动以下表达式 I 的值。
                Select Ch2 = ''                If @i = @J - 10  Begin
                            Select @Ch2 = '亿'
                            Select @Zero = 0
                end
                        
                If @i = @J - 6 Begin
                            Select @Ch2 = '万'
                            Select @Zero = 0
                end
                        
                if @i = @J - 2 Begin
                            Select @Ch2 = '元'
                            Select @Zero = 0
                end
                        
                If @i = @J 
                            Select @Ch2 = '整'
                            
            end            Select @ReturnValue = @ReturnValue + @Ch1 + @Ch2        select @i = @i+1
        end    --最后将多余的零去掉
        If CharIndex('仟仟',@ReturnValue) <> 0 
                Select @ReturnValue = Replace(@ReturnValue, '仟仟', '仟')    If CharIndex('佰佰',@ReturnValue) <> 0 
                Select @ReturnValue = Replace(@ReturnValue, '佰佰', '佰')        If CharIndex('零元',@ReturnValue) <> 0 
                Select @ReturnValue = Replace(@ReturnValue, '零元', '元')
        
            If CharIndex('零万',@ReturnValue) <> 0 
                Select @ReturnValue = Replace(@ReturnValue, '零万', '万')
       
            If CharIndex('零亿',@ReturnValue) <> 0
                Select @ReturnValue = Replace(@ReturnValue, '零亿', '亿')
        
            If CharIndex('零整',@ReturnValue) <> 0 
                Select @ReturnValue = Replace(@ReturnValue, '零整', '整')
        
        If CharIndex('零佰',@ReturnValue) <> 0 
                Select @ReturnValue = Replace(@ReturnValue, '零佰', '零')    If CharIndex('零仟',@ReturnValue) <> 0 
                Select @ReturnValue = Replace(@ReturnValue, '零仟', '零')    If CharIndex('元元',@ReturnValue) <> 0 
                Select @ReturnValue = Replace(@ReturnValue, '元元', '元')
        
        Select @ReturnValue 
    GO另一个
    CREATE FUNCTION GetChineseNum (@inputId money)   
    RETURNS Nvarchar(4000) AS  
    BEGIN 
    declare @rV Nvarchar(4000)declare @tmpstr Nvarchar(4000),@M Nvarchar(4000),@K Nvarchar(4000),@I numeric(38,2),
    @J int,@lastJ int,@LastV Nvarchar(10),@LastF Nvarchar(10),@LastE Nvarchar(10),@LastVE Nvarchar(10)
    set @I=@inputId
    select @tmpstr=N'零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿拾佰仟',@K=N'',@M=cast(cast(@I*100 as bigint) as varchar(800)),@J=len(@M),@LastVE=N''while @J>=1
    begin
    set @LastF=substring(@tmpstr, cast(substring(@m,len(@M)-@j+1,1) as bigint)+1,1)
    set @LastE=substring(@tmpstr,10+@J,1)
    if @LastF<>N'零'
    begin
    if @LastV=N'零'
    if (@lastJ>=7 and @j<=7) or (@lastJ>=11 and @j<=11 ) or (@lastJ>=3 and @j<=2)
    if @J<=2 and @lastJ<=3
    set @K=@K+@LastVE+@LastF+@LastE
    else
    set @K=@K+@LastVE+@LastV+@LastF+@LastE
    else
    set @K=@K+@LastV+@LastF+@LastE
    else
    set @K=@K+@LastF+@LastE
    select @lastJ=@j,@LastVE=N''
    end
    else
    begin
    if @LastVE=N'' and @lastJ>11 set @LastVE=N'亿'
    if @LastVE=N'' and @lastJ>7 and @lastJ<10 set @LastVE=N'万'
    if @LastVE=N'' and @lastJ>3 and @lastJ<6 set @LastVE=N'元'
    if @LastV<>N'零' set @lastJ=@j
    end
    set @LastV=@LastF
    set @J=@J-1
    end
    if @lastJ>=3 set @K=@K+N'元'
    if @lastJ>=2 set @K=@K+N'整'set @rv=@K return @rv
    END---------------------------------------------------
    select Num,dbo.getchineseNum(Num) as N'大写' from temp
    ------
    .5000 伍角
    .5600 伍角陆分
    .0100 壹分
    1.0000 壹元整
    10.1000 壹拾元壹角
    1000.0000 壹仟元整
    10000.3200 壹万零叁角贰分
    156823.8900 壹拾伍万陆仟捌佰贰拾叁元捌角玖分
    100000000.0000 壹亿元整
    100100000.0100 壹亿零壹拾万零壹分
    1234567890.9800 壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾元玖角捌分
      

  9.   

    找出输入月份的天数:
    drop proc month_proc
    go
    create proc month_proc @month varchar(20) as
    declare @month1 varchar(20)
    set @month1='2003-'+cast(cast(@month as int)+1 as varchar)+'-1'
    set @month='2003-'+cast(@month as varchar)+'-1'
    print (datediff(day,cast(@month as datetime),cast(@month1 as datetime)))exec month_proc 4
      

  10.   

    SELECT 
    (case when a.colorder=1 then d.name else '' end)表名,
    a.colorder 字段序号,
    a.name 字段名,
    (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识,
    (case when (SELECT count(*)
    FROM sysobjects
    WHERE (name in
               (SELECT name
             FROM sysindexes
              WHERE (id = a.id) AND (indid in
                        (SELECT indid
                      FROM sysindexkeys
                       WHERE (id = a.id) AND (colid in
                                 (SELECT colid
                                FROM syscolumns
                               WHERE (id = a.id) AND (name = a.name))))))) AND
           (xtype = 'PK'))>0 then '√' else '' end) 主键,
    b.name 类型,
    a.length 占用字节数,
    COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,
    isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,
    (case when a.isnullable=1 then '√'else '' end) 允许空,
    isnull(e.text,'') 默认值,
    isnull(g.[value],'') AS 字段说明 FROM  syscolumns  a left join systypes b 
    on  a.xtype=b.xusertype
    inner join sysobjects d 
    on a.id=d.id  and  d.xtype='U' and  d.name<>'dtproperties'
    left join syscomments e
    on a.cdefault=e.id
    left join sysproperties g
    on a.id=g.id AND a.colid = g.smallid  
    order by a.id,a.colorder
      

  11.   

    请大家写清楚:格式、含义和例子。
    留下E-Mail更好。
      

  12.   


    create table #(Parent_id int,item_id  int )
    insert into #(Parent_id,item_id) values(1,0)
    insert into #(Parent_id,item_id) values(2,1)
    insert into #(Parent_id,item_id) values(3,1)
    insert into #(Parent_id,item_id) values(4,2)
    insert into #(Parent_id,item_id) values(5,2)
    insert into #(Parent_id,item_id) values(6,3)
    insert into #(Parent_id,item_id) values(7,2)
    insert into #(Parent_id,item_id) values(8,3)
    insert into #(Parent_id,item_id) values(9,7)
    insert into #(Parent_id,item_id) values(10,9)set nocount on
    declare @ int,@i int
    set @=2
    declare @t table(Parent_id int,item_id  int,iv int)
    declare @t1 table(Parent_id int,item_id  int)
    insert into @t1
    select * from  #  where item_id=2
    set @i=1
    while  exists(select TOP 1 * from @t1)
    begin
     insert into @t(Parent_id ,item_id ,iv )
     select *,@i from @t1
     delete from  @t1
      insert into @t1    
      select * from  # where item_id  in (select Parent_id from @t where iv=@i)
      set @i=@i+1
    end
    select * from @t
    drop table #
    set nocount off
    处理TREE
      

  13.   

    create table # (a varchar(10),  b varchar(10),  c varchar(10), d int,  e int)
    insert into # values('a',        'b',      'c'    ,100 ,  null)
    insert into # values('a',        'b',      'c'    ,10 ,  null)
    insert into # values('d',        'f',      'j',    50 ,   null)
    insert into # values('a'      ,  'd'  ,    'f'  ,  30 ,   null)
    insert into # values('d'   ,     'f' ,     'a',    0 ,    100)
    select *,identity(int,1,1) as id into #1  from # ORDER BY D  
    declare @ int,@id int,@E INT 
    SELECT @=MAX(E) FROM #1
    SET @E=0
    update #1 set @=E=@ - @E  ,@ID= ID+1 ,@E=ISNULL(D,0)
    SELECT * FROM #1
    drop table #
    drop table #1
    UPDATE 用变量
      

  14.   

    对 CrazyFor(蚂蚁) 
    呵呵~~~联机帮助中的例子多好啊,还不如多看看联机帮助。:)
      

  15.   

    二维表 T(F1,F2,F3,F4,F5,F6,F7) 表示如下关系:
    ------------------------------------------------------------------------------
    │  学生ID  │ 学生姓名 │  课程ID  │ 课程名称 │   成绩   │  教师ID  │ 教师姓名 │
    │    S3    │   王五   │    K4    │   政治   │    53    │    T4    │  赵老师  │
    │    S1    │   张三   │    K1    │   数学   │    61    │    T1    │  张老师  │
    │    S2    │   李四   │    K3    │   英语   │    88    │    T3    │  李老师  │
    │    S1    │   张三   │    K4    │   政治   │    77    │    T4    │  赵老师  │
    │    S2    │   李四   │    K4    │   政治   │    67    │    T5    │  周老师  │
    │    S3    │   王五   │    K2    │   语文   │    90    │    T2    │  王老师  │
    │    S3    │   王五   │    K1    │   数学   │    55    │    T1    │  张老师  │
    │    S1    │   张三   │    K2    │   语文   │    81    │    T2    │  王老师  │
    │    S4    │   赵六   │    K2    │   语文   │    59    │    T1    │  王老师  │
    │    S1    │   张三   │    K3    │   英语   │    37    │    T3    │  李老师  │
    │    S2    │   李四   │    K1    │   数学   │    81    │    T1    │  张老师  │
    │   ....   │          │          │          │          │          │          │
    │   ....   │          │          │          │          │          │          │
    ------------------------------------------------------------------------------1.简述规范化思路  请以一句 T-SQL (Ms SQL Server) 或 Jet SQL (Ms Access) 作答
    2.如果 T 表还有一字段 F0 数据类型为自动增量整型(唯一,不会重复),
      而且 T 表中含有除 F0 字段外,请删除其它字段完全相同的重复多余的脏记录数据:3.列印各科成绩最高和最低的记录: (就是各门课程的最高、最低分的学生和老师)
      课程ID,课程名称,最高分,学生ID,学生姓名,教师ID,教师姓名,最低分,学生ID,学生姓名,教师ID,教师姓名4.按成绩从高到低顺序,列印所有学生四门(数学,语文,英语,政治)课程成绩: (就是每个学生的四门课程的成绩单)
      学生ID,学生姓名,数学,语文,英语,政治,有效课程数,有效平均分
      (注: 有效课程即在 T 表中有该学生的成绩记录,如不明白可不列印"有效课程数"和"有效平均分")5.按各科不及格率的百分数从低到高和平均成绩从高到低顺序,统计并列印各科平均成绩和不及格率的百分数(用"N行"表示): (就是分析哪门课程难)
      课程ID,课程名称,平均成绩,及格百分数6.列印四门课程平均成绩和及格率的百分数(用"1行4列"表示): (就是分析哪门课程难)
      数学平均分,数学及格百分数,语文平均分,语文及格百分数,英语平均分,英语及格百分数,政治平均分,政治及格百分数7.列印数学成绩第 10 名到第 15 名的学生成绩单
      或列印总成绩第 10 名到第 15 名的学生成绩单8.按不同老师所教不同课程平均分从高到低列印: (就是分析哪个老师的哪个课程水平高)
      教师ID,教师姓名,课程ID,课程名称,平均分9.统计列印各门课程成绩各分数段人数: (类似交叉报表)
      课程ID,课程名称,[100-85],[84-70],[69-60],[<60].删除其它字段完全相同的重复多余的脏记录数据delete a
    from t a,t b 
    where a.学生ID=b.学生ID and a.课程ID=b.课程ID and a.F0>b.F03.列印各科成绩最高和最低的记录  select a.课程ID,a.课程名称,a.[成绩] as 最高分,a.[学生ID],a.[学生姓名],a.[教师ID],a.[教师姓名],
            b.[成绩] as 最低分,b.[学生ID],b.[学生姓名],b.[教师ID],b.[教师姓名]
      from t a,t b,(select 课程ID,max([成绩]) 最高分,min([成绩]) 最低分 from t group by 课程ID) c
      where a.[成绩]=c.最高分 and a.课程ID=c.课程ID and b.[成绩]=c.最低分 and b.课程ID=c.课程ID 
      
    4.按成绩从高到低顺序,列印所有学生四门(数学,语文,英语,政治)课程成绩  select 学生id,
        max(case when 课程名称='数学' then 成绩 end) as '数学',
        max(case when 课程名称='语文' then 成绩 end) as '语文',
        max(case when 课程名称='英语' then 成绩 end) as '英语',
        max(case when 课程名称='政治' then 成绩 end) as '政治',
        count(成绩) as 有效课程数,
        (case when count(成绩)=0 then 0 else isnull(sum(成绩),0)/count(成绩) end)  as 有效平均分
      from t group by 学生ID
      order by 有效平均分 desc
     
    5.按各科不及格率的百分数从低到高和平均成绩从高到低顺序select 课程ID,max(课程名称) as 课程名称,left(avg(成绩),4) as 平均成绩,
       left(100.0* sum(case when 成绩 >=60 then 1 else 0 end)/count(课程ID) as 及格百分数
    from t group by 课程ID
    order by 及格百分数 desc,平均成绩 desc6.列印四门课程平均成绩和及格率的百分数select 
       left(max(case when 课程ID = 'k1' then ac end),4) as 数学平均分,
       left(max(case when 课程ID = 'k1' then passperc end),4)  as 数学及格百分数,
       left(max(case when 课程ID = 'k2' then ac end),4)  as 语文平均分,
       left(max(case when 课程ID = 'k2' then passperc end),4)  as 语文及格百分数,
       left(max(case when 课程ID = 'k3' then ac end),4)  as 英语平均分,
       eft(max(case when 课程ID = 'k3' then passperc end),4)  as 英语及格百分数,
       left(max(case when 课程ID = 'k4' then ac end),4)  as 政治平均分,
       left(max(case when 课程ID = 'k4' then passperc end),4)  as 政治及格百分数
    FROM
      (select 课程ID,left(avg(成绩),4) as ac,
      left(100.0* sum(case when 成绩 >=60 then 1 else 0 end)/count(成绩),4) as passperc
      from t group by 课程ID) a7. 列印总成绩第 10 名到第 15 名的学生成绩单 select top 6 学生ID, sum(成绩) as 总分  
     from t 
     where 学生ID not in (select top 9 学生ID from t group by 学生ID order by sum(成绩) desc )
     group by 学生ID 
     order by 总分 desc8.按不同老师所教不同课程平均分从高到低列印 select 教师ID,max(教师姓名),课程ID,max(课程名称) as 课程名称,avg(成绩) as 平均成绩
     from t 
     group by 课程ID,教师ID
     order by avg(成绩) desc
     
    9.统计列印各门课程成绩各分数段人数select 课程ID,课程名称,
       count(case when 成绩<=100 and 成绩>=85 then 课程ID end) as '[100-85]',
       count(case when 成绩<=84 and 成绩>=70 then 课程ID end) as '[84-70]',
       count(case when 成绩<=69 and 成绩>=60 then 课程ID end) as '[69-60]',
       count(case when 成绩<60 then 课程ID end) as '[<60]'
    from t
    group by 课程ID,课程名称
      

  16.   

    结果累加:
    tbl:
    mon    quantity       EndQuantity
    1        1              1
    2        2              2
    3        3              3
    4        4              4
    5        5              5
    6        6              6
    7        7              7
    8        8              8
    9        9              9
    10       10             10
    11       11             11
    12       12             12
    处理后
    mon    quantity       EndQuantity
    1        1              1
    2        2              3
    3        3              6
    4        4              10
    5        5              15
    6        6              21
    7        7              28
    8        8              36
    9        9              45
    10       10             55
    11       11             66
    12       12             78Update a Set a.EndQuantity=(select sum(totalquantity) from tbl b where b.mon<=a.mon) from tbl a
      

  17.   

    复制数据:
    -------------------------------------
    新表select * into newtable from table旧表insert into oldtable select * from table
      

  18.   

    declare  cursor_insert cursor for select c# from cs
    declare
    @i int
    open cursor_insert
    fetch cursor_insert into @i
    while @@fetch_status=0
    begin
      print @i
      fetch cursor_insert into @i
    end
    close cursor_insert
    deallocate cursor_insert
      

  19.   

    统计表ZL中姓李的人数:select COUNT(*) as [姓李共有(人)] from zl where xm LIKE '李%';
      

  20.   

    复制表结构:
       select Top 0 into #a from b or 
       select * into #a from b where 1=2
      

  21.   

    有这样得记录
    --------------
    table1
    id,value,  date
    1    150   2003-5-1
    2    23    2003-5-2
    3    50    2003-5-1
    4    241   2003-5-3
    5    60    2003-5-4
    6    52    2003-5-4
    ...  ...
    ..   ..
    .    .table2
    id   value
    1      1
    2      0
    3      1
    4      0
    5      1
    6      1
    ...
    ..
    .
    ------------我想select出来,table1某段具体时间内(按时间顺序),当table1.id=table2.id and table2.value=1 and table1.value值得总和>=某值得时候,都有那些记录
    把这些记录一一列出来比如按所给的例子,我想搜索2003-5-1到2003-5-10之间,table2.vaule=1对应的,当table1.value的值>250时停下来列出这样的结果:
    id value date
    1   150   2003-5-1
    3    50   2003-5-1
    5    60   2003-5-4=========================================
    select c.id,c.value,c.date from
      ( select id,value,(select coalesce(sum(b.value),0) from 
        ( select table1.* from table1  inner join table2 on table1.id=table2.id and   table2.value=1 ) b
        where b.id<a.id  ) as SumValue,date
        from 
         ( select table1.* from table1 inner join table2  on table1.id=table2.id and table2.value=1  ) a
    ) c
    where sumvalue<=250
    order by id,date
      

  22.   

    join的使用:
    create table #t(id int, a char)
    insert #t values (1, 'a')
    insert #t values (2, 'b')
    create table #t1(id int, a char)
    insert #t1 values (1, 'A')
    insert #t1 values (3, 'C')select * from #t inner join #t1 on #t.id = #t1.id
    id          a    id          a    
    ----------- ---- ----------- ---- 
    1           a    1           A(1 row(s) affected)
    select * from #t left join #t1 on #t.id = #t1.id
    id          a    id          a    
    ----------- ---- ----------- ---- 
    1           a    1           A
    2           b    NULL        NULL(2 row(s) affected)
    select * from #t right join #t1 on #t.id = #t1.id
    id          a    id          a    
    ----------- ---- ----------- ---- 
    1           a    1           A
    NULL        NULL 3           C(2 row(s) affected)
    select * from #t full join #t1 on #t.id = #t1.id
    id          a    id          a    
    ----------- ---- ----------- ---- 
    1           a    1           A
    NULL        NULL 3           C
    2           b    NULL        NULL(3 row(s) affected)
      

  23.   

    使INSERT 语句一次添加多个记录。要作到这一点,你需要把INSERT 语句与SELECT 语句结合起来,象这样:
    INSERT mytable (first_column,second_column)
    SELECT another_first,another_second
    FROM anothertable
    WHERE another_first=’Copy Me!’
      

  24.   

    cneptune(紫王星)
    你写也可以写成下面的样子:
    SELECT another_first,another_second INTO mytable FROM anothertable
    WHERE another_first=' Copy Me!'但条件是表mytable必须事先不存在。
      

  25.   

    用IN字句查询多个条件:
    select * from zl WHERE xm IN('条件1','条件2',...);
      

  26.   

    小写金额变大写
    CREATE PROCEDURE L2U @n_LowerMoney numeric(15,2) , @RETURES VARCHAR(200) OUT AS  
    BEGIN 
    Declare @v_LowerStr VARCHAR(200) -- 小写金额 
    Declare @v_UpperPart VARCHAR(200) 
    Declare @v_UpperStr VARCHAR(200) -- 大写金额
    Declare @i_I intSELECT @v_LowerStr=convert (varchar (200) ,(ROUND(@n_LowerMoney,2))) --四舍五入为指定的精度并删除数据左右空格
    print @v_LowerStr
    SELECT  @i_I = 1
    SELECT @v_UpperStr = ''while ( @i_I <= len(@v_LowerStr))
    begin
          select @v_UpperPart = case substring(@v_LowerStr,len(@v_LowerStr) - @i_I + 1,1)
                                WHEN  '.' THEN  '元'
                                WHEN  '0' THEN  '零'
                                WHEN  '1' THEN  '壹'
                                WHEN  '2' THEN  '贰'
                                WHEN  '3' THEN  '叁'
                                WHEN  '4' THEN  '肆'
                                WHEN  '5' THEN  '伍'
                                WHEN  '6' THEN  '陆'
                                WHEN  '7' THEN  '柒'
                                WHEN  '8' THEN  '捌'
                                WHEN  '9' THEN  '玖'
                                END
                              + 
                                case @i_I
                                WHEN  1  THEN  '分'
                                WHEN  2  THEN  '角'
                                WHEN  3  THEN  ''
                                WHEN  4  THEN  ''
                                WHEN  5  THEN  '拾'
                                WHEN  6  THEN  '佰'
                                WHEN  7  THEN  '仟'
                                WHEN  8  THEN  '万'
                                WHEN  9  THEN  '拾'
                                WHEN  10  THEN  '佰'
                                WHEN  11  THEN  '仟'
                                WHEN  12  THEN  '亿'
                                WHEN  13  THEN  '拾'
                                WHEN  14  THEN  '佰'
                                WHEN  15  THEN  '仟'
                                WHEN  16  THEN  '万'
                                ELSE ''
                                END
    SELECT  @v_UpperStr = ltrim(rtrim(@v_UpperPart)) + @v_UpperStr
    SELECT  @i_I = @i_I + 1
    end-- 对壹元以下的金额的处理 
    if ( '元' = substring(@v_UpperStr,1,1))
    begin
         SELECT @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    endif ( '零' = substring(@v_UpperStr,1,1))
    begin
         SELECT @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    endif ( '角' = substring(@v_UpperStr,1,1))
    begin
         SELECT @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    endif ( '分' = substring(@v_UpperStr,1,1))
    begin
         SELECT @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    endif ('整' = substring(@v_UpperStr,1,1))
    begin
         SELECT @v_UpperStr = '零元整'
    end  
    SELECT  @RETURES=@v_UpperStr
    print @v_UpperStr
    END
      

  27.   

    为了分,大家什么都贴上来了。
    我写两句:
    1、CREATE TABLE tGoGoGo
       (
       int iGo not null
       )
    2、DROP TABLE tGoGoGo本来一心向前冲,看到这么多贴人,只好DROP,放弃啦!
      

  28.   

    从表a中删除字段b=1的记录
    delete from a where b=1
    哈哈,太简单了
      

  29.   

    --在某个数据库下查找所有未加密存储过程文本中的关键字。
    CREATE Proc PFind @String Varchar(30) As
    Begin
    set nocount on
      if object_id('tbl') is null
    create table Tbl(cText text)  Declare @Sql Varchar(1000),@pName Varchar(60)  Declare pCursor Cursor Local Forward_Only For Select Name From Sysobjects Where Type='P'  OPEN pCursor  FETCH NEXT FROM pCursor into @pName  While @@Fetch_Status=0 
      Begin
    Set @Sql=''
    --Insert Into @Tbl(pName) Values(@Name)
    Set @Sql='Insert Into tbl Execute sp_helptext '+@pName
    Execute(@Sql)
    If Exists(Select 1 From tbl Where cText Like '''%''+@String+''%''')
    Print @pName
    Delete From Tbl
      FETCH NEXT FROM pCursor into @pName
      End  Close pCursor
      Deallocate pCursor
    set nocount off
    End-------------因自己编写,请高手注意--------------
    ---我的insert into tbl中,一个存储过程有几行,tbl中出现几行,而不能合并到一行中。
    ---所以也可以create table Tbl(cText varchar(1000) null)
    --------------------------------------------------
      

  30.   

    取得工作站(当前机子)名称。HOST_NAME ( )