Solved

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

Posted on 2013-10-22
4
398 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

762 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

21 Experts available now in Live!

Get 1:1 Help Now