看看这个例子吧!
会对你有帮助
不知道是不是这个USE pubs
GO
SELECT   Category = 
      CASE type
         WHEN 'popular_comp' THEN 'Popular Computing'
         WHEN 'mod_cook' THEN 'Modern Cooking'
         WHEN 'business' THEN 'Business'
         WHEN 'psychology' THEN 'Psychology'
         WHEN 'trad_cook' THEN 'Traditional Cooking'
         ELSE 'Not yet categorized'
      END,
   CAST(title AS varchar(25)) AS 'Shortened Title',
   price AS Price
FROM titles
WHERE price IS NOT NULL
ORDER BY type, price
COMPUTE AVG(price) BY type
GO

解决方案 »

  1.   

    不是这个,这是SQL在线帮助的,我也看过了。没找到,所以才来看的。:(
      

  2.   

    不知道你要什么结果第一种:select case when @Method='A' then 'a' 
                when @Method='B' then 'b' 
                when @Method='C' then 'c' 
                ......
                when @Method='K' then 'k' 
                end第二种:if @Method='A' 
    begin
      select 'a'
    end else
    if @Method='B' 
    begin
      select 'b'
    end else
    if @Method='C' 
    begin
      select 'c'
    end else
    ......
    if @Method='K' 
    begin
      select 'k'
    end 
      

  3.   

    我想要用select case来做
    实现执行像第二种样子的beign....end程序块,怎么做?
    不用if else
    谢谢。
      

  4.   

    Create Procedure Doit
    @Method nvarchar(20)
    As
    Begin
        Select 'Method'= 
              Case
                 When @Method='A' Then 'a'
                 When @Method='B' Then 'b'
                 …………
                 When @Methoe='E' Then 'e'
              End
        From tablename
    End
      

  5.   

    去掉Form 表,直接用变量可以吗?
    还有我要用begin....end
    如果实在不行,我就用if ...else...
    算了.select @Method
              Case
                 When @Method='A' Then 
    begin
    'a'
    end
                 When @Method='B' Then
    begin
     'b'
    end
                 …………
              End