반응형
여러 매개 변수가 있는 EXEC sp_executesql
매개 변수를 에 전달하는 방법EXEC sp_executesql
진술이 정확합니까?
이것이 제가 지금 가지고 있는 것이지만, 오류가 발생하고 있습니다.
alter PROCEDURE [dbo].[usp_getReceivedCases]
-- Add the parameters for the stored procedure here
@LabID int,
@RequestTypeID varchar(max),
@BeginDate date,
@EndDate date
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @statement nvarchar(4000)
set @statement = N'select SentToLab,
FROM dbo.vEmailSent
WHERE SentToLab_ID=@LabID and convert(date,DateSent) >= @BeginDate
and CONVERT(date, datesent) <= @EndDate
and RequestType_ID in ( @RequestTypeID )
EXEC sp_executesql @statement,N'@LabID int', @LabID, N'@BeginDate date', @BeginDate,N'@EndDate date', @EndDate, @RequestTypeID=@RequestTypeID
END
요청 유형ID는 쉼표로 구분된 정수 목록으로, "1,2,3,4,5"와 같습니다.
여기 제 시도 #2가 있습니다, 또한 실패했습니다.
declare @statement nvarchar(4000)
SET @statement =' select SentToLab_ID
FROM dbo.vEmailSent
WHERE
SentToLab_ID='+@LabID+' and convert(date,DateSent) >= '+@BeginDate +'
and CONVERT(date, datesent) <= '+@EndDate+'
and RequestType_ID in ('+ @RequestTypeID+' )
group by FileStream_ID, SentToLab_ID'
EXEC(@statement)
피연산자 유형 충돌: 날짜가 int와 호환되지 않습니다.
다음은 간단한 예입니다.
EXEC sp_executesql @sql, N'@p1 INT, @p2 INT, @p3 INT', @p1, @p2, @p3;
당신의 전화는 이런 것이 될 것입니다.
EXEC sp_executesql @statement, N'@LabID int, @BeginDate date, @EndDate date, @RequestTypeID varchar', @LabID, @BeginDate, @EndDate, @RequestTypeID
이것도 작동합니다...때로는 실제 EXEC 호출 외부에서 매개 변수의 정의를 구성해야 할 수도 있습니다.
DECLARE @Parmdef nvarchar (500)
DECLARE @SQL nvarchar (max)
DECLARE @xTxt1 nvarchar (100) = 'test1'
DECLARE @xTxt2 nvarchar (500) = 'test2'
SET @parmdef = '@text1 nvarchar (100), @text2 nvarchar (500)'
SET @SQL = 'PRINT @text1 + '' '' + @text2'
EXEC sp_executeSQL @SQL, @Parmdef, @xTxt1, @xTxt2
사용해야 하는 경우sp_executesql
와 함께OUTPUT
변수:
EXEC sp_executesql @sql
,N'@p0 INT'
,N'@p1 INT OUTPUT'
,N'@p2 VARCHAR(12) OUTPUT'
,@p0
,@p1 OUTPUT
,@p2 OUTPUT;
아마도 이것은 도움이 될 것입니다.
declare
@statement AS NVARCHAR(MAX)
,@text1 varchar(50)='hello'
,@text2 varchar(50)='world'
set @statement = '
select '''+@text1+''' + '' beautifull '' + ''' + @text2 + '''
'
exec sp_executesql @statement;
이것은 아래와 같습니다.
select @text1 + ' beautifull ' + @text2
언급URL : https://stackoverflow.com/questions/28481189/exec-sp-executesql-with-multiple-parameters
반응형
'programing' 카테고리의 다른 글
plt.show() 창을 최대화하는 방법 (0) | 2023.09.04 |
---|---|
스크롤 후 탐색 모음 색을 변경하시겠습니까? (0) | 2023.09.04 |
내 ember.js 경로 모델이 호출되지 않는 이유는 무엇입니까? (0) | 2023.09.04 |
CSS 파일을 즉시 교체(그리고 새로운 스타일을 페이지에 적용) (0) | 2023.09.04 |
IIS에서 X-Powered-By ASP를 안전하게 제거할 수 있습니까?NET 헤더? (0) | 2023.09.04 |