SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Calling a Stored Procedure from a View


Calling a Stored Procedure from a View

Author
Message
CrazyMan
CrazyMan
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3076 Visits: 1597
Hi All
I got stuck with a problem, i need to call a SP from a View

Say for example i got a SP called SP_XXX, i need to call this from a view called Vw_YYY

Like Create view Vw_YYY as

--- We have to call the SP here




i cant create a temp table inside a view to store the values from the SP and then select that temp table

Can any one suggest wethere this is possible???

Cheers
GilaMonster
GilaMonster
SSC Guru
SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)

Group: General Forum Members
Points: 229138 Visits: 46344
Not possible. A view is a single select statement.

Could you explain a bit more why you're trying to do this?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Lowell
Lowell
SSC Guru
SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)

Group: General Forum Members
Points: 73603 Visits: 40974
sounds like you want the results of sp_who in a view for example?
simply sp_helptext sp_XXX, and read the code....maybe you can simply lift the code, or maybe you can convert it to a function, so you can create a view of the function...it really depends...a lot of the sp_'s have cursors and otehr things that can make it difficult to do a view.


the code to call a stored proc and display it is already easily accomplished...so can you explain why you want to do this?

Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
CrazyMan
CrazyMan
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3076 Visits: 1597
Hi Gila
I found a work around, but iam facing error, the work around is

select * from OpenRowset ( 'SQLOLEDB','Server=(Local);TRUSTED_CONNECTION=YES;','Exec Temp.dbo.Software') as a


Temp.dbo.Software is the SP that returns me values

but when i tried to run this i am getting a error

Cannot process the object "Exec Temp.dbo.Software'". The OLE DB provider "SQLNCLI" for linked server "(null)" indicates that either the object has no columns or the current user does not have permissions on that object.


Does this strike any bells
GilaMonster
GilaMonster
SSC Guru
SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)

Group: General Forum Members
Points: 229138 Visits: 46344
CrazyMan (7/22/2008)
Hi Gila
I found a work around, but iam facing error, the work around is

select * from OpenRowset ( 'SQLOLEDB','Server=(Local);TRUSTED_CONNECTION=YES;','Exec Temp.dbo.Software') as a


Ouch. That's extreme. And a bad idea.

Please explain why you need the results of a proc in a view.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


CrazyMan
CrazyMan
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3076 Visits: 1597
HI Gial
I am planning to cache this on Java, this is the requriment, Basically i need to check wether the record is there on a table or not, i can check this on the View and return the value with the status called True, but when the record is not there on the table then i need to display the value with status as False, i cant do this in View, can i??, so i used a SP and then calling that SP on this view, is there any other way to do this??


Cheers
GilaMonster
GilaMonster
SSC Guru
SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)

Group: General Forum Members
Points: 229138 Visits: 46344
Can't java call stored procedures?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


CrazyMan
CrazyMan
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3076 Visits: 1597
it can call but it cant cache, it can only cache View, thats where the problem comes in
GilaMonster
GilaMonster
SSC Guru
SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)

Group: General Forum Members
Points: 229138 Visits: 46344
Or, if you prefer (assuming no parameters)


CREATE VIEW IsRowThere AS
SELECT CASE WHEN Row_Count >0 THEN 'True' ELSE 'False' END As ItsThere
FROM
(SELECT COUNT(*) AS row_Count FROM Sometable Where SomeConditions) x
GO



Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


GSquared
GSquared
SSC Guru
SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)

Group: General Forum Members
Points: 58917 Visits: 9730
Since you're not passing any parameters to the proc/view, it should be possible with a view.

I don't have your tables, so here's a generic version:


create view RowExists
as
select (cast 1 as bit) as RE
from dbo.Table1
where exists
(select *
from dbo.Table1)
union
select top 1 (cast 0 as bit)
from sys.all_objects
where not exists
(select *
from dbo.Table1)



You might be able to use something like that to get the job done.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search