| |

VerySource

 Forgot password?
 Register
Search
View: 1258|Reply: 10

select reads the stored procedure return set with parameters, finds the read statement

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-22 09:00:01
| Show all posts |Read mode
Write a stored procedure as follows:
CREATE PROCEDURE dbo.getPauseDays
    @htongInfoIdx int
AS
declare @ p1 binary (16)
declare @ p2 binary (16)
create table # (c1 text)
insert # select ""
SELECT @ p1 = textptr (c1) FROM #
--Declare a cursor
DECLARE tb CURSOR LOCAL
  FOR
  SELECT textptr (pausedays)
  FROM hetongpauseinfo where uidx = @htongInfoIdx
OPEN tb
FETCH tb INTO @ p2
WHILE @@ fetch_status = 0
BEGIN
UPDATETEXT # .c1 @ p1 NULL null hetongpauseinfo.pausedays @ p2
FETCH tb INTO @ p2
END
CLOSE tb
DEALLOCATE tb
select c1 from #
drop table #
GO

In the query analyzer, exec getPauseDays 12 can access the query set, but it doesn't work in the select statement. . select a. * from (getPauseDays 12) as a read like this will not work
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-2-1 08:00:01
| Show all posts
--A simple example
use pubs
go

create proc pc
as
select title_id from titles

create table T (col varchar (50))
insert T exec pc

select * from T
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-2-1 11:18:01
| Show all posts
The stored procedure contains select ...
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-2-1 13:09:02
| Show all posts
God, forgive me for being foolish and not understanding what my friends upstairs mean. . . I can run this proc in the query analyzer, but in the foreground, I use select to call this proc's recordset. I won't write a statement.
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-2-1 13:27:01
| Show all posts
Execute getPauseDays 12 directly in the foreground
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-2-1 18:09:01
| Show all posts
Execute directly? How to write >? .... and (exec getPauseDays 12) like '% 20005-01-01%' ... This is part of the query. . I want the recordset returned by it to be judged like, can't run? Checked a lot of information, just ignore it. . > _ <
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-2 02:54:01
| Show all posts
it's the only way
insert into #t
exec getPauseDays 12

select * from #t
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-2 07:36:01
| Show all posts
insert into #t
exec getPauseDays 12

This is to insert the result set produced by exec getPauseDays 12 into #t
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-2-2 09:09:01
| Show all posts
There must be a method to execute stored procedures in the connection object in the foreground
It doesn't work, write a function that returns a table type
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-2 13:00:02
| Show all posts
select * from openrowset ('sqloledb', 'trusted_connection = yes', 'SET FMTONLY OFF; SET NOCOUNT ON; EXEC your database name: getPauseDays 12')

But this is more perverted.You better write a function that returns a table type instead of a stored procedure
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