Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tSQLt.ResultSetFilter - error when procedure parametr is sql keyword #4

Closed
blepa opened this issue Jun 29, 2016 · 2 comments
Closed

Comments

@blepa
Copy link

blepa commented Jun 29, 2016

Hello,

I noticed that when the value of the parameter of tested procedure is equal to the sql keyword - procedure tSQLt.ResultSetFilter returns an error:

System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'AS'.

Test script:

USE tSQLt_Example
GO

IF OBJECT_ID('dbo.uspForTest') IS NOT NULL
DROP PROCEDURE dbo.uspForTest
GO

CREATE PROCEDURE dbo.uspForTest
(
@InParam01 VARCHAR(20)
)
AS
BEGIN
SELECT @InParam01 [InParam01]
ENd
GO

IF OBJECT_ID('dbo.test_uspForTest') IS NOT NULL
DROP PROCEDURE dbo.test_uspForTest
GO

-- ok test case
CREATE PROCEDURE dbo.test_uspForTest
AS
BEGIN

CREATE TABLE #uspForTest
(
InParam01 VARCHAR(20)
)

DECLARE @command VARCHAR(4000)
DECLARE @InParam01 VARCHAR(20)

SET @InParam01 = 'AT'

SET @command = 'EXEC dbo.uspForTest @InParam01 = ' + @InParam01

INSERT INTO #uspForTest
EXEC tSQLt.ResultSetFilter
@ResultsetNo = 1
, @command = @command

SELECT * FROM #uspForTest
END
GO

EXEC tSQLt.Run '[dbo].[test_uspForTest]'
GO

-- error test case
ALTER PROCEDURE dbo.test_uspForTest
AS
BEGIN

CREATE TABLE #uspForTest
(
InParam01 VARCHAR(20)
)

DECLARE @command VARCHAR(4000)
DECLARE @InParam01 VARCHAR(20)

SET @InParam01 = 'AS'

SET @command = 'EXEC dbo.uspForTest @InParam01 = ' + @InParam01

INSERT INTO #uspForTest
EXEC tSQLt.ResultSetFilter
@ResultsetNo = 1
, @command = @command

SELECT * FROM #uspForTest
END
GO

EXEC tSQLt.Run '[dbo].[test_uspForTest]'
GO

@blepa
Copy link
Author

blepa commented Jun 29, 2016

Solution:

SET @InParam01 = '''AS'''

Issue to CLOSE.

@mbt1
Copy link
Collaborator

mbt1 commented Jul 15, 2016

This is not a ResultSetFilter issue. But it looks like you figured that out already.

@mbt1 mbt1 closed this as completed Jul 15, 2016
mbt1 pushed a commit that referenced this issue Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants