2010-03-31 71 views
-1

如何傳遞參數在SQL查詢如何傳遞參數在SQL查詢

的executeQuery(「從EMP刪除其中EMPNO = auguement);

+0

請詳細解釋你的問題。像這樣的問題沒有人能夠得到答案。 – Salil 2010-03-31 09:11:36

+0

你需要更具體。你能舉一個例子,或者更詳細地解釋你想要做什麼? – Blorgbeard 2010-03-31 09:11:43

+1

是的,有用的東西,比如什麼編程語言和什麼數據庫。 – Paddy 2010-03-31 09:14:40

回答

1

你真的需要發佈更多,情報,但作爲首發....

-- Passing a parameter for a Where clause in a SQL query 

Declare @UserId int 
Set @UserId = 12 

Select * From dbo.Users 
Where UserId = @UserId 


-- Passing a parameter for use in a Stored Procedure 

Declare @UserId int 
Set @UserId = 12 

Execute dbo.usp_Fetch_User_ById @UserId 
0

傳給你首先需要有一個存儲過程,會消耗參數的參數:後

create procedure sp_AddNumbers 
(@int1 int, 
@in2 int) 
as 

    select @in1 + @int2 

go 

與代碼中調用它如

exec sp_Addnumbers @int1=3, @int2=9 

exec sp_Addnumbers 3, 9