基本上在我的" master sproc"我将检查一些输入参数以确定要调用哪个从属sproc,然后将该从属sproc的输出传递回调用者。使用SQL Server。
以下代码不起作用:
CREATE PROCEDURE dbo.master
@a char(1)
, @b char(1)
AS
IF @a > @b
EXEC dbo.proc_a @a, @b;
ELSE
EXEC dbo.proc_b @a, @b;
GO
此代码只返回" 0",而不是结果。
答案 0 :(得分:3)
T-SQL代码,例如" master" proc就像:
CREATE PROCEDURE dbo.master
@a char(1)
, @b char(1)
AS
IF @a > @b
EXEC dbo.proc_a @a, @b;
ELSE
EXEC dbo.proc_b @a, @b;
GO
Result sets returned by the called procedure will be returned to the client just like if run directly from the master proc.
修改强>
以下是使用评论代码的示例:
CREATE TABLE dbo.TransactionsA (col1 int);
INSERT INTO dbo.TransactionsA VALUES(1);
CREATE TABLE dbo.TransactionsB (col1 int);
INSERT INTO dbo.TransactionsB VALUES(2);
GO
CREATE PROCEDURE [dbo].[GetData]
@A int = 0
, @B int = 0
AS
IF (@A > @B)
EXEC dbo.GetAData @A, @B;
ELSE
EXEC dbo.GetBData @A, @B;
GO
CREATE PROCEDURE [dbo].[GetAData]
@A int = 0
, @B int = 0
AS
SET NOCOUNT ON;
SELECT * FROM TransactionsA;
GO
CREATE PROCEDURE [dbo].[GetBData]
@A int = 0
, @B int = 0
AS
SET NOCOUNT ON;
SELECT * FROM TransactionsB;
GO
EXEC dbo.GetData 1,2; --returns 2
EXEC dbo.GetData 2,1; --returns 1
EXEC dbo.GetData 1,1; --returns 2
GO
答案 1 :(得分:0)
我不知道你为什么要比较字符,但问题可能在于你SP之前的定义,我试过代码并且工作正常返回数据
<span>V2.0.<# DateTime.Now.ToString("%M") #><# DateTime.Now.ToString("dd") #></span>