Using Stored Procedure in View with join

—Create Table with values

Create table testopenquerytable(P1 varchar(10),P2 varchar(10),Val varchar(10))

insert into testopenquerytable values (‘test1′,’test2′,’HelloWorld’)

–Create Proc

Create proc dbo.testopenquery (@parm1 varchar(10),@param2 varchar(10)) as

set nocount on

Select @parm1 as p1,@Param2 as p2

–Create View

Create view dbo.testopenqueryview

as select a.p1,a.P2,b.Val from openquery(local, ‘

SET FMTONLY OFF Exec dbname.dbo.testopenquery ”test1”,”test2”’) a, testopenquerytable b where a.P1=b.P1 and a.P2=b.P2

–Note

–Here ”test1” proc paramenter denoes two single quotes in the above line

–Test View

Select * from testopenqueryview

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s