1
对于SQL Server Expertise,我有一个不太难的问题。虽然我有另一种选择,但我想知道这可以解决在SQL Server 2005中使用CASE语句。在SQL Server 2005中使用case语句的不同表格中的相同字段
我有各种具有相同列的类别表。我需要的是根据类别调用SELECT语句。下面就是我试图做
ALTER PROCEDURE [dbo].[Sgi_DropDownListItemsLoadByTblName]
@Category int
AS
BEGIN
SET NOCOUNT ON;
CASE
when @Category = 1 Then Select [ID],[OptionText],[Description] From dbo.Sgi_ListItems_Denomination
when @Category = 2 Then Select [ID],[OptionText],[Description] From dbo.Sgi_ListItems_Drink
when @Category = 3 Then Select [ID],[OptionText],[Description] From dbo.Sgi_ListItems_Education
when @Category = 4 Then Select [ID],[OptionText],[Description] From dbo.Sgi_ListItems_Ethnicity
when @Category = 5 Then Select [ID],[OptionText],[Description] From dbo.Sgi_ListItems_Kids
when @Category = 6 Then Select [ID],[OptionText],[Description] From dbo.Sgi_ListItems_Religion
when @Category = 7 Then Select [ID],[OptionText],[Description] From dbo.Sgi_ListItems_Smoking
end
END
当我试图创建该SP在CASE语句产生错误的代码
我知道这可以通过使用简单的IF语句,但我做渴望知道如何使用CASE语句来完成。
任何人都可以帮助我。
感谢分享你的时间。
谢谢马特!但这不是我所期待的。 – IrfanRaza 2010-07-15 19:01:15