Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Calling a Stored Procedure from a View Expand / Collapse
Author
Message
Posted Tuesday, July 22, 2008 10:51 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, July 3, 2014 10:20 AM
Points: 770, Visits: 1,596
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
Post #538636
Posted Tuesday, July 22, 2008 10:59 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:17 PM
Points: 42,450, Visits: 35,505
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 2008, MVP
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

Post #538643
Posted Tuesday, July 22, 2008 11:19 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:24 PM
Points: 12,881, Visits: 31,816
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #538659
Posted Tuesday, July 22, 2008 11:27 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, July 3, 2014 10:20 AM
Points: 770, Visits: 1,596
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
Post #538668
Posted Tuesday, July 22, 2008 11:31 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:17 PM
Points: 42,450, Visits: 35,505
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 2008, MVP
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

Post #538672
Posted Tuesday, July 22, 2008 11:57 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, July 3, 2014 10:20 AM
Points: 770, Visits: 1,596
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

Post #538700
Posted Tuesday, July 22, 2008 11:59 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:17 PM
Points: 42,450, Visits: 35,505
Can't java call stored procedures?


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
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

Post #538702
Posted Tuesday, July 22, 2008 12:02 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, July 3, 2014 10:20 AM
Points: 770, Visits: 1,596
it can call but it cant cache, it can only cache View, thats where the problem comes in
Post #538705
Posted Tuesday, July 22, 2008 12:03 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:17 PM
Points: 42,450, Visits: 35,505
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 2008, MVP
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

Post #538708
Posted Tuesday, July 22, 2008 12:03 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 15,444, Visits: 9,596
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
Post #538709
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse