Declaring variables

Results 1 to 2 of 2

Thread: Declaring variables

  1. #1
    Join Date
    Dec 1969

    Default Declaring variables

    I’m trying to figure a way that I can declare a variable to be used for connecting to a known linked server. I have some sql code that uses a cursor to sift through a table whereby the IP address is used to connect to other servers. Some updating occurs and I do something like the following:<BR><BR> DECLARE @ComputerIP varchar(15)<BR><BR> -- Some more code for looping through each record from the table<BR><BR> SET @ComputerIP = &#039;;<BR> SELECT * FROM [@ComputerIP].GRIPANET.dbo.MEDNET_VERSION_LOG<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default It's a hack, but you..

    .. could use dynamic SQL<BR><BR>DECLARE @ComputerIP VARCHAR(15),<BR> @SQL VARCHAR(1024)<BR><BR>SELECT @ComputerIP = &#039;;<BR>SELECT @SQL = &#039;SELECT * FROM &#039; + @ComputerIP + &#039;.GRIPANET.dbo.MEDNET_VERSION_LOG&#039;<BR>EX EC (@SQL)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts