THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Peter DeBetta's SQL Programming Blog

Peter DeBetta's blog about programming in SQL Server using technologies such as T-SQL, .NET, CLR, C#, VB, Visual Studio, and SQL Server Management Studio.

Things You Don't Learn in School

I was speaking to my friend Byer today, discussing the use of the OpenQuery function to get to some data from Oracle (in a linked server) - a requirement of the system on which he was working. More specifically, he needed to lookup a single value based in Oracle and return it to SQL Server to use in a query. Since OpenQuery does not allow a variable to be used for the SQL statement, and since this particular query needed a variable, dynamic execution was going to have to be used to create the correct SELECT statement sing the OpenQuery function. So, after sorting out these little details, we were finally at a point where we could use the value coming back from the dynamically executed SQL statement.

So, I will keep the OpenQuery stuff out of this to show what happened. Neither of us had never tried the following little morsel of code; and we discovered there is something wrong with it.

DECLARE @OneValue Table (Val Varchar(11))
DECLARE @sExec Varchar (1000)

SET @sExec = 'SELECT au_id FROM authors where au_lname = ''MacFeather'''

INSERT INTO @OneValue
EXECUTE (@sExec)

SELECT * FROM @OneValue

Now that I think about it, I'm going to give the answer in my next post. Enjoy....

Published Monday, June 26, 2006 12:59 PM by Peter W. DeBetta

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(required) 
Submit

About Peter W. DeBetta

Peter DeBetta works for Microsoft as an Application Platform Technology Strategist, specializing in strategies, design, implementation, and deployment of Microsoft SQL Server and .NET solutions. Peter writes courseware, articles, and books – most recently the title Introducing SQL Server 2008 from Microsoft Press. Peter speaks at conferences around the world, including TechEd, SQL PASS Community Summit, DevTeach, SQL Connections, DevWeek, and VSLive!

When Peter isn’t working, you can find him singing and playing guitar (click here to hear an original song by Peter), taking pictures, or simply enjoying life with his wife, son, and daughter.
Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement