我正在使用SQL Server 2005与asp.net C#。有没有办法避免TSQL中的条件?
我的网站上有一个搜索查询使用不同的参数。
fromAge as tinyint
toAge as tinyint
fromHeight as tinyint
toHeight as tinyint
gender as tinyint
withImage as bit
region as tinyint
astrologicaSign as tinyint
我从第一次使用这些参数进行搜索和拯救自己的搜索喜好搜索表,然后在Users
表从我选择符合要求满足用户使用。
问题是一些值可以有条件像例如withImage(位)这意味着现在我需要有if语句,检查我是否提供0或1 withImage,然后执行选择ie。如果withImage = 1,那么查询的位置将是图片1 <>'0',否则根本没有条件。
我确实以10个嵌套if语句结束了初始查询(我简化了这个例子)。
是否有办法避免它,除了动态SQL?
什么,但如果声明。想想10个嵌套的if。 – eugeneK 2010-07-13 12:04:36