Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-10-22
4
Medium Priority
?
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 66

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 66

Accepted Solution

by:
Jim Horn earned 2000 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 66

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

688 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