在查询中苦苦挣扎。做了几处改动,但无法让它发挥作用。
这些过程本身作为查询工作,但在另一个过程中调用时不起作用;因为我在调试
时看不到填充的变量值感谢任何帮助?
Exec dbo.usr_GetLastDate @TableName, @LastTransDate
EXEC dbo.usr_GetRecCount @TableName, @RecCount
ALTER PROCEDURE [dbo].[usr_GetLastDate]
-- Add the parameters for the stored procedure here
@TableName SYSNAME,
@OUTDATE date Output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @SQLCommand NVARCHAR(MAX) =
N'SELECT @OUTDATE=MAX(TRANSDATE) FROM ' + QUOTENAME(@TableName);
EXECUTE [dbo].[sp_executesql]
@sqlCommand, N'@OUTDATE DATE OUTPUT', @OUTDATE=@OUTDATE OUTPUT;
END
ALTER PROCEDURE [dbo].[usr_GetRecCount]
-- Add the parameters for the stored procedure here
@TableName SYSNAME,
@OUTINT int output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @SQLCommand NVARCHAR(MAX) =
N'SELECT @OUTINT=COUNT(SYMBOL) FROM ' + QUOTENAME(@TableName);
EXECUTE [dbo].[sp_executesql]
@sqlCommand, N'@OUTINT INT OUTPUT', @OUTINT=@OUTINT OUTPUT;
END
答案 0 :(得分:0)
如果您正在使用visual studio 您可以在“变量”窗口中看到所有变量值。表达式仅在具有范围时显示值,但有时它们的行为方式与我们不同。
所以我的建议是你应该使用" Variables"窗口查看所有变量及其值。
答案 1 :(得分:0)
将OUTPUT变量传递给过程
时,需要使用关键字OUTPUTresult[j] = (char*) malloc(100);
答案 2 :(得分:0)
有效的最终代码。谢谢大家
** Main Procedure **
Exec dbo.usr_GetLastDate @TableName, @LastTransDate OUTPUT
EXEC dbo.usr_GetRecCount @TableName, @RecCount OUTPUT
ALTER PROCEDURE [dbo].[usr_GetLastDate]
-- Add the parameters for the stored procedure here
@TableName SYSNAME,
@OUTDATE date Output
--<@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @SQLCommand NVARCHAR(MAX) =
N'SELECT @OUTDATE=MAX(TRANSDATE) FROM ' + QUOTENAME(@TableName);
EXECUTE [dbo].[sp_executesql]
@sqlCommand, N'@OUTDATE DATE OUTPUT', @OUTDATE=@OUTDATE OUTPUT;
END
ALTER PROCEDURE [dbo].[usr_GetRecCount]
-- Add the parameters for the stored procedure here
@TableName SYSNAME,
@OUTINT int output
--<@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @SQLCommand NVARCHAR(MAX) =
N'SELECT @OUTINT=COUNT(SYMBOL) FROM ' + QUOTENAME(@TableName);
EXECUTE [dbo].[sp_executesql]
@sqlCommand, N'@OUTINT INT OUTPUT', @OUTINT=@OUTINT OUTPUT;
END