我是K2
和SQL Server
的新手。
我想向存储过程中添加一个参数,该参数随后将与相应视图和表单的K2
智能对象绑定。
当前它有1个参数lang
,它是来自K2
Smartform View的标签的输入。
我在同一视图上添加了标签labelHideInactiveCompany
,我想将该值传递到我的存储过程中,但是我不知道该怎么做。
有人告诉我,我需要更改的第一件事是存储过程,然后更新smart object
。
我可以知道应该采取什么步骤吗?谢谢。
下面是我的查询:
USE [K2_Database]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [Config].[usp_ListBusinessUnit]
@lang varchar(2) = null
as
SELECT EntityId
,EntityCode
,EntityName
,CO.OrganizationDesc
,EntityAbbreviation
,PBU.ParentBusinessUnitName
,EntityAttribute
,EntityOwnedCompany
,EntityPrincipal
,EntityAccountingProgram
,EntityCurrency
,EntityCurrenyExchRate
,BU.CountryRegion
,EntityNCOwnedIndustry
,BU.IsActive
,BU.CreatedBy
,CreateOn
,BU.ModifiedBy
,BU.ModifiedOn
,BU.Lang AS LangAbbr
FROM Config.BusinessUnit BU
LEFT JOIN Config.Organization CO on BU.OrganizationId = CO.OrganizationId
LEFT JOIN Config.ParentBusinessUnit PBU on BU.ParentBusinessUnitId = PBU.ParentBusinessUnitId
ORDER BY CASE WHEN @lang = 'cn' THEN BU.Lang END,
CASE WHEN @lang = 'en' THEN BU.Lang END DESC,
EntityName
答案 0 :(得分:2)
添加参数很简单,我使用了占位符,因为我们不知道您想调用什么参数或它的数据类型。
您需要做的就是在ALTER
语句中添加参数。
ALTER procedure [Config].[usp_ListBusinessUnit]
@lang varchar(2) = null,
@newParamName newParamType -- Your new stuff
as
-- the rest of your stored proc here
现在不要忘记对存储的proc中的新参数进行操作。
答案 1 :(得分:1)
听起来您想要此参数和此WHERE子句:
ALTER procedure [Config].[usp_ListBusinessUnit]
@lang varchar(2) = null,
@hideInactiveCompany bit = 0 -- Add this parameter!
as
SELECT EntityId
,EntityCode
,EntityName
,CO.OrganizationDesc
,EntityAbbreviation
,PBU.ParentBusinessUnitName
,EntityAttribute
,EntityOwnedCompany
,EntityPrincipal
,EntityAccountingProgram
,EntityCurrency
,EntityCurrenyExchRate
,BU.CountryRegion
,EntityNCOwnedIndustry
,BU.IsActive
,BU.CreatedBy
,CreateOn
,BU.ModifiedBy
,BU.ModifiedOn
,BU.Lang AS LangAbbr
FROM Config.BusinessUnit BU
LEFT JOIN Config.Organization CO on BU.OrganizationId = CO.OrganizationId
LEFT JOIN Config.ParentBusinessUnit PBU on BU.ParentBusinessUnitId = PBU.ParentBusinessUnitId
WHERE (@hideInactiveCompany = 0 OR BU.IsActive = 1) -- Use the parameter!
ORDER BY CASE WHEN @lang = 'cn' THEN BU.Lang END,
CASE WHEN @lang = 'en' THEN BU.Lang END DESC,
EntityName