(select @@servername from OPENDATASOURCE('SQLNCLI', 'Data Source=Servername ;Integrated Security=SSPI') .DBNAME.dbo.BSC )

For the above query i need to parameterised the 'Data Source=Servername .

How it can be done .
more ▼

asked May 17, 2012 at 07:19 AM in Default

jhunu gravatar image

90 29 30 31

@Jhunu Just in case you missed it, for the whole month of May, accepting an answer will add 50 points to the profile. Your profile shows that if you start accepting answers to your questions, you can certainly get more than 500 points :)
May 17, 2012 at 09:22 AM robbin
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

You can use dynamic sql for that


SET @ServerName = N'ServerName'

EXEC ('select TOP 1 @@servername from OPENDATASOURCE(''SQLNCLI'', ''Data Source='+ @ServerName + ' ;Integrated Security=SSPI'').master.dbo.spt_values')
more ▼

answered May 17, 2012 at 09:07 AM

robbin gravatar image

1.6k 1 3 5

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: May 17, 2012 at 07:19 AM

Seen: 1821 times

Last Updated: May 17, 2012 at 09:22 AM