| |

VerySource

 Forgot password?
 Register
Search
View: 869|Reply: 6

!!!!!! Find the result set of stored procedure return !!!!!!!!!!!!!!!

[Copy link]

2

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-12 09:30:01
| Show all posts |Read mode
The query conditions are dynamically specified, that is: select field1, field2, field3 into #temp from testtable where 1 = 1 + dynamically pass the stored procedure judgment conditions (such as: and field1 = 2) How can I solve this problem? And then use: select * from #temp but at this time #temp has been invalidated, it is really a headache, please also give pointers to one or two.
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Ireland

Post time: 2020-4-16 21:15:01
| Show all posts
In the stored procedure select * from #temp
But at this time, we must ensure that this select statement is the only or at least the first executed statement in the stored procedure.
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-16 22:00:02
| Show all posts
Or, another way; you can write a function that returns a table
See the help example for specifics; it is clear.
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-17 02:45:01
| Show all posts
CREATE FUNCTION SalesByStore (@storeid varchar (30))
RETURNS TABLE
AS
if @storeid = ''
RETURN (SELECT title, qty
      FROM sales s, titles t
      WHERE s.stor_id = @storeid and
      t.title_id = s.title_id)
else if ...
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-6-7 08:00:01
| Show all posts
I don't know what you are doing

exec('
select field1,field2,field3 from testtable where'+queryStr+'
')
Reply

Use magic Report

0

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-6 11:45:01
| Show all posts
The stored procedure can directly return the result set of your choice, the temporary table is indeed redundant
Reply

Use magic Report

2

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-14 11:00:01
| Show all posts
There is no desired answer.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list