sql存儲過程傳入參數
1、使用SQL語句
--a)方式一
--exec存儲過程名稱參數名='值'
execP_Titles_ByType@type='business'
go
--b)方式二
--exec存儲過程名稱參數值
execP_Titles_ByType'business'
2、可視化操作
a.在資料庫中找到要執行的存儲過程
b.右擊存儲過程,在出現的菜單中選擇執行存儲過程選項
c.在新出現的對話框中,在對應的參數後面的值列填入對應的參數值
d.填寫完參數值,最後點擊確定,然後查詢結果會出現
圖-b
『貳』 存儲過程中動態SQL中的傳入參數為datetime類型的問題
你先調試一下,少了個@和begin、end
另外,拼接變數不能在字元串內啊,這樣沒用
create procere [dbo].[baobiao1]
@date1 datetime,
@date2 datetime
as
set nocount on
begin
Set XACT_ABORT ON;
Begin Tran
Declare @SQL1 varchar(8000)
Declare @SQL2 varchar(8000)
--Set @SQL='Create view A as select ....'
--Exec(@SQL)
if exists (SELECT * FROM sysobjects WHERE name = 'report1')
begin
drop view report1
end
set @SQL1='create view report1 as select s.englishName,s.belongzu,count(*) kaitai,
jiachan=(case s.shiftName when ''甲'' then sum(s.realproc) else 0 end),
jiachaochan=(case s.shiftName when ''甲'' then sum(s.realproc-s.singleplan*s.workminute/60) else 0 end),
yichan=(case s.shiftName when ''乙'' then sum(s.realproc) else 0 end),
yichaochan=(case s.shiftName when ''乙'' then sum(s.realproc-s.singleplan*s.workminute/60) else 0 end),
bingchan=(case s.shiftName when''丙''then sum(s.realproc) else 0 end),
bingchaochan=(case s.shiftName when''丙''then sum(s.realproc-s.singleplan*s.workminute/60) else 0 end),
dingchan=(case s.shiftName when''丁''then sum(s.realproc) else 0 end),
dingchaochan=(case s.shiftName when''丁''then sum(s.realproc-s.singleplan*s.workminute/60) else 0 end),
(case when s.shiftName =''甲''then sum(p.cibushu) else 0 end) jiacibu,
(case when s.shiftName =''乙''then sum(p.cibushu) else 0 end) yicibu,
(case when s.shiftName =''丙''then sum(p.cibushu) else 0 end) bingcibu,
(case when s.shiftName =''丁''then sum(p.cibushu) else 0 end) dingcibu,
(case when s.shiftName =''甲''then sum(p.kaijianshu) else 0 end) jiakaijian,
(case when s.shiftName =''乙''then sum(p.kaijianshu) else 0 end) yikaijian,
(case when s.shiftName =''丙''then sum(p.kaijianshu) else 0 end) bingkaijian,
(case when s.shiftName =''丁''then sum(p.kaijianshu) else 0 end) dingkaijian
from HistoryPro1 s left outer join kaijianjicibu2 p on s.wholeDate = p.wholeDate AND
s.MachineID = p.MachineID AND
s.shiftName = p.shiftName where s.wholeDate >=『+@date1+『 and s.wholeDate <=』+@date2=『 group by s.englishName,s.belongzu,s.shiftName'
exec(@SQL1)
commit Tran
end
set nocount on
GO
『叄』 SQL Server 如何執行 帶參數的 存儲過程
帶參數的存儲過程執行方法如下:
(1)調用通用數據訪問類:SqlHelper,執行SqlHelper.ExecuteNonQuery()方法
(2)使敬譽春用示例:SqlHelper.ExecuteNonQuery(conn,CommandType.StoredProcere,sqlexec,myparm)
(3)其中傳遞的4個參數如下:
「conn」:為鏈接字元
「CommandType.StoredProcere」:表示要執亮耐行的SQL存儲過程類型
「sqlexec」:要執行的SQL存儲過程
「myparm」:為傳遞的參虛沖數,它需要參數的初始化、賦予參數名稱、設定類型、長度和值等
(4)當ExecuteNonQuery()執行select 查詢時,結果總是返回-1。ExecuteNonQuery()執行Update、Insert和Delete語句時,返回值為該命令所影響的行數。
『肆』 sql資料庫中怎樣調用帶參數的存儲過程
在sql
server中
執行帶參數的存儲過程
exec+空格+存儲過程名+空格+參數
多個參數的話用逗號分隔
傳出參數要加output
例如:
exec
P_GetIntegratedFluxOneMoment
@StartTableName,@ColName,@StartTime,@StartValue
output
其中@StartTableName,@ColName,@StartTime,@StartValue都是前面已經定義好的變數
傳入參數也可以不用變數
直接寫值也行
程序中調用的話看你用什麼語言了
各個語言的調用方法不一樣
『伍』 sql 存儲過程 傳入兩組數組參數
declare@nnvarchar(500)
declare@mnvarchar(500)
set@n='1,2,3,4,5'
set@m='a,b,c,d,e'
createtable#tb(nVARCHAR(500),mVARCHAR(500))
while(1=1)
begin
if(Charindex(',',@n)=0andCharindex(',',@m)=0)
begin
insertinto#tbvalues(@n,@m)
break
end
insertinto#tbvalues(Substring(@n,1,Charindex(',',@n)-1),Substring(@m,1,Charindex(',',@m)-1))
set@n=Right(@n,Len(@n)-Charindex(',',@n))
set@m=Right(@m,Len(@m)-Charindex(',',@m))
end
select*from#tb
droptable#tb
ps:要做好校驗!
『陸』 sql server 中 一個要輸入參數和輸出參數的存儲過程。
1、首先我們需要打開SQL Server Managment管理工具,新建一個表。