Something wrong with my query, what am I doing wrong?

Posted on 2011-10-31
Last Modified: 2012-05-12
There is something wrong with my query, what am I doing wrong?
select	mmatter, mdesc1, 
		tklast + ', ' + tkfirst + ' (' + tkinit + ')' as WA,
		sum(hwacur) as MTD_Billable_hours,
		sum(hwaytd) as YTD_Billable_hours
from df_dwtkmat , df_dwcontrol, matter, timekeep
where matter in (select	distinct  mmatter from timecard
					where ttk='02500'
					and tworkdt between getdate()-30 and getdate())
and rectype=4020
and defvalue=pe
and matter=mmatter
and watty=tkinit
group by mmatter, mdesc1, 
		tklast + ', ' + tkfirst + ' (' + tkinit + ')'
having sum(hwacur) <> 0 or
		sum(hwaytd)<> 0
order by 		mmatter, mdesc1, 
		tklast + ', ' + tkfirst + ' (' + tkinit + ')'

Open in new window

Question by:VBBRett
    LVL 28

    Expert Comment

    Well, to be honest with you, we don't know unless you tell us.
    LVL 15

    Expert Comment

    What is the error message you're getting?
    LVL 68

    Accepted Solution

    It's literally impossible for us to tell which column comes from which table.

    You need to specify an alias for every table in the query and prefix every column with a table alias.

    Then we'd have a chance of determining what might be wrong / missing.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    T-SQL To Select PiD In Two Hobbies 3 32
    SQL Server Remove all trailing commas 10 54
    SQL help 5 42
    Help with SQL joins 9 32
    by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    755 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

    18 Experts available now in Live!

    Get 1:1 Help Now