Using SQL code to read a filename

5 pts.
SQL Query
SQL statements
Can you write a SQL query that will read PDF filename from a dir and then match the filename to a data element in a table having the same name? For instance, the filename is 12345.pdf where 12345 is actually an invoice number. Can the query read the filename and then locate the same invoice number from within a column in a table that contains a list of invoice numbers?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Yes you can do this. You can use xp_dirtree to get a list of files in a folder and drop the returned recordset into a table then loop through the rows in the table processing the filenames.


Hi, not to put too fine of a point on this but I would disagree with this answer. The question is can one use SQL to access a PC directory structure. SQL can only access RDBMS data. The suggested approach is not truly using SQL; where SQL consists of SELECT, CREATE, REVOKE, etc.

Discuss This Question: 2  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    I guess Meandyou is right, but if the question had been answered paying strict attention to the words, I guess the answer would have been a simple NO. Maybe the question asker did not use the proper words for what he needed. Who knows.
    85,885 pointsBadges:
  • Denny Cherry
    The odds of someone knowing the difference between SQL, T/SQL, PL/SQL etc is minimal in most cases. If they had asked for an ANSI SQL solution to the problem, then obviously there isn't one. It is extremely common for people who are working with databases (SQL Server, DB2, etc) to simply refer to the language they use as SQL. Is this accurate? No. Is it common place? Yes. Does that mean that the users should be beat down with semantics? No. People go to forum sites to get an answer to a question that is causing them problems. In a lot of cases English isn't there first language (and I have no idea if that is the case here) so trying to get across the concept that ANSI SQL and SQL are different and that they should be references as such is a loosing battle which will simply make the users not come back. If this person needed more clarification they can simply ask for more clarification. Either this person got the answer they needed, they didn't need the answer any more, or they forgot they posted the question here.
    69,130 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: