如何使用相同的WHERE列创建过程

时间:2012-11-05 09:30:15

标签: sql sql-server tsql

如何创建一个过程且WHERE列是相同的?

WHERE列为QuotationNo

这是程序签名:

create procedure (QUO1 int, QUO2 int, QUO3 int, QUO4 int)

输出:

Quote     price     quantity
---------------------------------
1234       2000        1000
5678       2500        4000
9012        3000        4500 
3456        1000        1000

谢谢,

Captain16

2 个答案:

答案 0 :(得分:1)

CREATE PROCEDURE NameMyProc
    @QUO1 int, @QUO2 int, @QUO3 int, @QUO4 int
AS
    select quote, price, quantity
     from tbl
    where quotationno in (@qu01, @qu02, @qu03, @qu04)
GO

您还可以创建一个更灵活的表值函数,例如

CREATE FUNCTION dbo.NameMyFunction (
    @QUO1 int, @QUO2 int, @QUO3 int, @QUO4 int
) RETURNS TABLE AS RETURN
    select quote, price, quantity
     from tbl
    where quotationno in (@qu01, @qu02, @qu03, @qu04)
GO

-- Example usage:
SELECT * FROM dbo.NameMyFunction(1234, 5678, 9012, 3456) T

答案 1 :(得分:0)

如果您在运行时提供quo值

create proc [test]
 (QUO int(11))
as 
begin
select quote,price,quantity from table where quote=@QUO 
end