本文介绍了如何将设置结果值传递给另一个值..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DECLARE @CompID NVARCHAR(MAX),

@sql NVARCHAR(MAX),

@Result NVARCHAR(MAX);

SET @CompID = 245;

SET @sql ='SELECT COUNT(Cw.LocWeight)FROM LocationWeight Cw,其中Cw.CompanyID = 245';

SET @Result = @sql ;



我尝试了什么:



如何传递@sql结果值为@Result

DECLARE @CompID NVARCHAR(MAX),
@sql NVARCHAR(MAX),
@Result NVARCHAR(MAX);
SET @CompID = 245;
SET @sql = 'SELECT COUNT(Cw.LocWeight) FROM LocationWeight Cw where Cw.CompanyID = 245';
SET @Result = @sql;

What I have tried:

how to pass @sql result value to @Result

推荐答案

DECLARE @CompID NVARCHAR(MAX),
@sql NVARCHAR(MAX),
@Result int;
SET @CompID = 245;
SET @sql = 'SELECT @Result= COUNT(Cw.LocWeight) FROM LocationWeight Cw where Cw.CompanyID = 245'; 

 EXEC SP_EXECUTESQL 
        @Query  = @sql
      , @Params = N'@Result int OUTPUT'
      , @Result  = @Result OUTPUT 

	  select @Result





来自 []


DECLARE @sql NVARCHAR(MAX), @Result NVARCHAR(MAX);
SET @sql = 'A string of text';
SET @Result = @sql;
SELECT @Sql AS Sql, @Result AS Result



哪个选择:


Which selects:

Sql                Result
A string of text   A string of text


这篇关于如何将设置结果值传递给另一个值..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 22:31