Solved

T-SQL Query Through ODBC--Not All Data is "There"

Posted on 2013-10-22
4
401 Views
Last Modified: 2013-10-23
Hello:

Attached is an Excel spreadsheet whose data I access within a separate app and through an ODBC connection to the spreadsheet.

I need to build T-SQL syntax (i.e. select * from) to accommodate the fact that the Employee and Employee ID columns have blanks.  For instance, for Frank Balsamo, you can tell that he has seven courses.  But, how do I get the ODBC connection to "understand" that?

In other words, I guess I need to use PARTITION BY or something like that within the T-SQL syntax in order to "fill in" the Employee and Employee ID fields.  That way, the ODBC connection will know not to leave blanks in those columns.

I hope that makes sense.

Anyway, can you all please help me with the T-SQL syntax on this?

Please, also, let me know if you have any questions.

Thanks!  Much appreciated!

TBSupport
Book2.xlsx
0
Comment
Question by:TBSupport
  • 3
4 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39592325
>through an ODBC connection to the spreadsheet.
Sounds like the spreadsheet is eliminating these values when they duplicate with what's above.  
Since the connection is only a connection, and does not alter data, that's what you get.

I propose you build a view based on this table, that goes something like this..
SELECT n.Employee, n.EmployeeID, ClassCourse ID, CompletedDate, ExpirationDate, Completed
FROM YourTable yt
   JOIN (SELECT DISTINCT Employee, EmployeeID FROM YourTable) n ON yt.Employee = n.Employee

Open in new window

0
 
LVL 1

Author Comment

by:TBSupport
ID: 39592493
Thanks!

I slightly modified your query, and the app is saying that there is a syntax error in the "FROM" clause.  I don't see any issues, though, do you?  Incidentally, EmployeeTrainingCourses$ is the tab in the Excel workbook that I'm connecting to.

Below is the revised query.

TBSupport

SELECT a.Employee, a.EmployeeID, ClassCourseID, CompletedDate, ExpirationDate, Completed
FROM [EmployeeTrainingCourses$] b
   JOIN (SELECT DISTINCT Employee, EmployeeID FROM [EmployeeTrainingCourses$]) a
ON b.Employee = a.Employee
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 39592502
Try this..
JOINing on the ID's and not the names
Prefixed every column in the SELECT clause
SELECT a.Employee, a.EmployeeID, b.ClassCourseID, b.CompletedDate, b.ExpirationDate, b.Completed
FROM [EmployeeTrainingCourses$] b
   JOIN (SELECT DISTINCT Employee, EmployeeID FROM [EmployeeTrainingCourses$]) a 
ON b.EmployeeID = a.EmployeeID

Open in new window

0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39592508
Also, the spreadsheet had a lot of spaces in the column names, so you'll want to eyeball these and make sure it's correct.  T-SQL can't handle spaces in object names, so whenever you see then you'll need square brackets surrounging them.

e.g. EmployeeName is okay, Employee{space}Name is not, [Employee Name] is ok
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now