从选择查询中设置参数值

时间:2012-06-06 10:31:41

标签: sql-server-2008

我有两个参数

DECLARE @nOdc_Id VARCHAR(50)
DECLARE @nProject_Id VARCHAR(50)

选择查询

Select nOdc_Id ,nProject_Id  From ProjectTable Where ProjectId='53'

现在我想将参数的值设置为

Set @=nOdc_Id =nOdc_Id 
And @nProject_Id =nProject_Id 

请帮助我如何在StoredProcedure中实现这一点。

3 个答案:

答案 0 :(得分:14)

Select @nOdc_Id = nOdc_Id, 
       @nProject_Id = nProject_Id  
From ProjectTable 
Where ProjectId = 53

答案 1 :(得分:6)

你可以这样做。还有更多的方法。

SET @nOdc_Id = (select nOdc_Id From ProjectTable Where ProjectId='53');
SET @nProject_Id = (select nProject_Id From ProjectTable Where ProjectId='53');

答案 2 :(得分:2)

像这样:

DECLARE @nOdc_Id VARCHAR(50) 
DECLARE @nProject_Id VARCHAR(50) 

Select @nOdc_Id = nOdc_Id From ProjectTable Where ProjectId='53' 
select @nProject_Id  = nProject_Id From ProjectTable Where ProjectId='53'