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管理工具,新建一个表。