February 11, 2011 at 7:42 am
This should be a simple question and hopefully a simple answer. I usually build stored procs directly for use in SQL Server 2005, however now I have a case where I need to run an OPENQUERY SQL string against a different linked database server.
In my Stored proc, I am concantenating several strings together to form the actual SELECT statement for this other database. Before I hit the EXEC sp_executesql statement, is there a way to print or see the string that is stored in my @SQLQuery variable?
Here is the actual concatenations that I am doing:
SET @SQLQuery = 'SELECT * from OPENQUERY([PI], SELECT x.time, x.value as Rate, x2.value as Surge '
SET @SQLQuery = @SQLQuery + 'FROM piarchive..piinterp2 x '
SET @SQLQuery = @SQLQuery + 'INNER JOIN piarchive..piinterp2 x2 on x.time=x2.time '
SET @SQLQuery = @SQLQuery + 'WHERE x.tag= ''' + @rateTag + ''' '
SET @SQLQuery = @SQLQuery + 'AND x.time> ''' + @startDate + ' ' + '06:59:00 AM '
SET @SQLQuery = @SQLQuery + 'AND x.time> ''' + @endDate + ' ' + '07:01:00 AM '
SET @SQLQuery = @SQLQuery + 'AND x.timestep=''1m'' AND x2.tag= ''' + @surgeTag + ''''
Thanks for the information.
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy