0

How to parameterize a call to a stored procedure in an NL()

Hi all,

I managed to execute a stored procedure from within an =NL(..) function. Now I'd like to know how I may parametereize the invocation of the sproc.

This is what you need in order to use a stored procedure:

Jfx enforces you to only use SELECT statements. Use TSQL OPENQUERY for this
Example:
SELECT Kontaktnummer, Firmenname1, PLZ, Ort, StrasseHausnummer
FROM OPENQUERY([loopback], 'navaid.dbo.getContactDataFromSegment ''SEG000004''')

This will execute the sproc getContactDataFromSegment

The first parameter of OPENQUERY is a linked server. I wanted to use my databes server as a linked server to itself, so I created the linked server Iand named it "loopback" but any other name will do.

Here is how I created the linked server to itself (I forgot where I found this code, but thanks to the author)
exec sp_addlinkedserver @server = N'loopback',
@srvproduct = N'',
@provider = N'SQLOLEDB',
@datasrc = @@servername
Go

Try it out in SQL Management studio:
SELECT Kontaktnummer, Firmenname1, PLZ, Ort, StrasseHausnummer
FROM OPENQUERY([loopback], 'navaid.dbo.getContactDataFromSegment ''SEG000004''')


Now I can use the execute sproc statement in my NL()

=NL("table";"SQL=SELECT Kontaktnummer, Firmenname1, PLZ, Ort, StrasseHausnummer FROM OPENQUERY([loopback], 'navaid.dbo.getContactDataFromSegment ''SEG000004''')";{"Kontaktnummer"."Firmenname1"."PLZ"."Ort"."StrasseHausnummer"})



My problem now is, how can I parameterize the segment number ( SEG000004 ) to be read from a cell i.e. A4



Any help is welcome
Thanks
Sascha

2 comments

Please sign in to leave a comment.