此代码返回的第一个匹配字符串可能是SQL查询,具有避免这种歧义或问题的任何想法。
CREATE PROCEDURE test
@name1 NVARCHAR(MAX),
@name2 NVARCHAR(MAX)
AS
BEGIN
IF @name1 = 'test'
PRINT '1'
ELSE IF (@name1 = 'test1' AND @name2 = 'test')
PRINT '2'
END
//----------------------------------------------
EXEC test 'test1','test' //I want to return '2' but its return '1'
/*
NOW I WANT TO ACHIEVE '2' WITHOUT CHANGING ORDER
HOW WE CAN ACHIEVE
*/
我的代码逻辑如下:我正在创建用于插入,更新和删除的存储过程,现在我想添加另一个操作(如join),所以我想将相同的表名作为参数传递,但其名称要高于>
请参见示例,我将尝试:
ALTER PROCEDURE [dbo].[spAllOperation]
@action NVARCHAR(MAX) = NULL,
@tableName NVARCHAR(MAX) = NULL,
@P1_string NVARCHAR(MAX) = NULL,
@P2_string NVARCHAR(MAX) = NULL,
@P3_string NVARCHAR(MAX) = NULL,
@P4_string NVARCHAR(MAX) = NULL,
@P5_int INT = NULL,
@P6_int INT = NULL,
@P7_int INT = NULL,
@P8_int INT = NULL,
@P11_date DATE = NULL
AS
BEGIN
IF @action = 'INSERT'
BEGIN
IF @tableName = 'Student_Details'
INSERT INTO Student_Details (Name, Roll_No, DoB, Gender, Addr, contact_No, Col_Id, R_Id)
VALUES (@P1_string, @P5_int, @P11_date, @P2_string, @P3_string, @P4_string, @P6_int, @P7_int)
ELSE IF @tableName = 'College_Details'
INSERT INTO College_Details
VALUES (@P1_string, @P2_string, @P3_string, @P4_string)
END
ELSE IF @action = 'UPDATE'
BEGIN
IF @tableName = 'Romm_Details'
UPDATE Romm_Details
SET status = @P1_string
WHERE Id = @P5_int
END
ELSE IF @action = 'DELETE'
BEGIN
PRINT '3'
END
ELSE IF @action='JOIN'
IF @tableName = 'Student_Details'
/*
MY PROBLEM IS HERE WHEN I PASS THE TABLE NAME ITS MUST BE GOING TO CURRENT BLOCK
.
.
*/
BEGIN
END
END