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 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply