看看这个例子吧!
会对你有帮助
不知道是不是这个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
会对你有帮助
不知道是不是这个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
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
实现执行像第二种样子的beign....end程序块,怎么做?
不用if else
谢谢。
@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
还有我要用begin....end
如果实在不行,我就用if ...else...
算了.select @Method
Case
When @Method='A' Then
begin
'a'
end
When @Method='B' Then
begin
'b'
end
…………
End