0

I have a Database and i want to execute few queries on it, and the results of the queries i.e. message, has to be comapared in my code if it is expected or not. Please let me know how to capture the output of the SQL queries in any variable that can be used later in code for comparision.

1

2 Answers 2

0

Try the following Method :

  • Create a Table with the Same structure as of your Procedure output
  • Insert the Result of the SP Execution to the Table
  • Compare your Query result with the Table

Like this

CREATE PROCEDURE dbo.uSp_Temp
AS
SELECT
    GETDATE() "MyDate"

DECLARE @T TABLE
(
    MyDate DATE
)

INSERT INTO @T
EXEC uSp_Temp

SELECT
    *
    FROM @T
Sign up to request clarification or add additional context in comments.

Comments

0

You can use Temp tables or temp variable to save the result set of a query.

Below is the sample for temp table

create table #temp (id int)

insert into #temp 
select 1 as id

select * from #temp

Below is sample for Temp variable

declare  @temp table (id int)

insert into @temp 
select 1 as id

select * from @temp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.