本文介绍了我需要在存储过程中进行多个选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的存储过程:

this is my stored procedure:

ALTER PROCEDURE [dbo].[cls_search]
	@serarchtype int=null,   // this mode use for multiple select
	@cls_code varchar(20)=null,// other twoo are column
	@cls_name varchar(30)=null
AS
BEGIN
		if (@serarchtype = 1)
		BEGIN
		select cls_code,cls_name from Cls_master where cls_code=@cls_code
		END
		else
		BEGIN
		select cls_code,cls_name from Cls_master where cls_name=@cls_name
		END
END







i希望使用1作为@serarchtype和@cls_code但是没有给@cls_name然后首先选择查询

执行





否则

使用2作为@serarchtype和@cls_name但不给@cls_code然后第二个选择查询执行







plz帮帮我




i want to use 1 as @serarchtype and @cls_code but no give @cls_name then first select query
execute


otherwise
use 2 as @serarchtype and @cls_name but no give @cls_code then second select query execute



plz help me

推荐答案

DECLARE @strNonsense_02 [nvarchar](66)
SET @strNonsense_02 = 'nonesense_02'
DECLARE @searchtype[int]
SET @searchtype = 1
BEGIN
		if (@searchtype = 1)
		BEGIN
		select @strNonsense_01 --cls_code,cls_name from Cls_master where cls_code=@cls_code
		END
		else
		BEGIN
		select @strNonsense_02 -- from Cls_master where cls_name=@cls_name
		END
END



退货:


Returns:

nonesense_01



和:


And:

BEGIN
		if (@searchtype = 65)
		BEGIN
		select @strNonsense_01 --cls_code,cls_name from Cls_master where cls_code=@cls_code
		END
		else
		BEGIN
		select @strNonsense_02 -- from Cls_master where cls_name=@cls_name
		END
END



返回:


Returns:

nonsense_02



对数据不了解,这就是我可以冒险解决的问题...


Not privy to the data, that's all I can venture from the description of the problem ...


这篇关于我需要在存储过程中进行多个选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 05:05