无法在select中选择变量(存储过程) [英] Can not assign variable in select (store procedure)

查看:110
本文介绍了无法在select中选择变量(存储过程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ALTER procedure [dbo].[spDepartmentWorkingSelectAll]

as
set nocount on
declare @SAM float
declare @factor_error float
select [id],
    [date_working],
    [department_id],
    (select top 1 departments.name from departments where departments.id = department_id) as department_name,
    [employee_count],
    [product_quantity],
    [real_time],
    [labor_unit],
    [product_id],
    (select top 1 products.code from products where products.id = [product_id]) as product_code,
    [product_quantity_error],
    @SAM = dbo.fnSam([product_id]), -- SAM
    @SAM as sam,
    @factor_error = dbo.fnFactorError([product_id],[product_quantity],[product_quantity_error]), -- factor error
    @factor_error as factor_error
    (@SAM * 60)/2 as real_output ,
    @SAM * @factor_error as reward_unit
    ((@SAM + @factor_error) * 8)/32 as expected_output
from [department_working]





我尝试了什么:



i希望在select stament中指定变量进行操作,但我在sql server 2008中的存储过程无法运行。请各位帮助我。谢谢



What I have tried:

i want assign variable in select stament for operation but my store procedure in sql server 2008 can not run. every one please help me. thanks

推荐答案

请通过这个例子

从SQL Server中的存储过程调用函数 [ ^ ]

同时删除重复列
Please through this example
Calling a Function From a Stored Procedure in SQL Server[^]
Also remove repetitive columns


这篇关于无法在select中选择变量(存储过程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆