SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL errors
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jrobin747
Starting Member

USA
48 Posts

Posted - 08/12/2013 :  10:26:20  Show Profile  Reply with Quote
I'm using SQL Server Management Studio 2008 and I'm still learning how to do joins and alias properly.

I am getting red squiggly lines for my alias names
STM.UserID The multi-part identifier "STM.UserID" could not be bound
MerAppEqL Invalid object name 'MerAppEqL'

I thought by me having FROM MerchantAppEquipmentLease MerAppEqL
I wouldn't have problems with MerAppEqL


DECLARE @x_strStartDate VARCHAR (10),
@x_strEndDate VARCHAR (10)

SET @x_strStartDate= '03/04/2013'
SET @x_strEndDate= '08/10/2013'

SELECT (FirstName + '' + LastName)AS [Sales Team Member], MerApp.Assignedto,
SUM (MerAppEqL.MonthlyPayment)AS [$ Leases Funded]
FROM MerchantAppEquipmentLease MerAppEqL
INNER JOIN MerchantApplication MerApp ON STM.UserID = MerApp.Assignedto
INNER JOIN MerchantAppEquipment MrAppEq ON MerApp.ApplicationID = MrAppEq.ApplicationID
INNER JOIN MerAppEqL ON MrAppEq.LeaseNumber= MerAppEqL.LeaseNumber
INNER JOIN Users USR ON STM.UserID = usr.UserID
WHERE MerAppEqL.FundedDate BETWEEN @x_strStartDate AND @x_strEndDate
AND MerAppEqL.LeaseStatus = 'Approved'

GROUP BY MerAppEql.SubmitBy, usr.FirstName, usr.LastName, MerApp.Assignedto
ORDER BY usr.FirstName, usr.LastName

James K
Flowing Fount of Yak Knowledge

3569 Posts

Posted - 08/12/2013 :  10:30:38  Show Profile  Reply with Quote
When you use STM.UserID on the join condition, SQL Server immediately looks for a table (or an alias) with the name STM that is in the list of tables you have listed so far in the WHERE clause. It doesn't find any, and hence the error.

Is STM a table? Or should it be more like this?
....
FROM    MerchantAppEquipmentLease MerAppEqL
        INNER JOIN MerchantApplication MerApp ON MerAppEqL.UserID = MerApp.Assignedto
        INNER JOIN MerchantAppEquipment MrAppEq ON MerApp.ApplicationID = MrAppEq.ApplicationID
....
Go to Top of Page

MuMu88
Aged Yak Warrior

547 Posts

Posted - 08/12/2013 :  11:26:33  Show Profile  Reply with Quote
One more...

quote:
Originally posted by jrobin747

I'm using SQL Server Management Studio 2008 and I'm still learning how to do joins and alias properly.

I am getting red squiggly lines for my alias names
STM.UserID The multi-part identifier "STM.UserID" could not be bound
MerAppEqL Invalid object name 'MerAppEqL'

I thought by me having FROM MerchantAppEquipmentLease MerAppEqL
I wouldn't have problems with MerAppEqL


DECLARE @x_strStartDate VARCHAR (10),
@x_strEndDate VARCHAR (10)

SET @x_strStartDate= '03/04/2013'
SET @x_strEndDate= '08/10/2013'

SELECT (FirstName + '' + LastName)AS [Sales Team Member], MerApp.Assignedto,
SUM (MerAppEqL.MonthlyPayment)AS [$ Leases Funded]
FROM MerchantAppEquipmentLease MerAppEqL
INNER JOIN MerchantApplication MerApp ON STM.UserID = MerApp.Assignedto
INNER JOIN MerchantAppEquipment MrAppEq ON MerApp.ApplicationID = MrAppEq.ApplicationID
INNER JOIN MerAppEqL ON MrAppEq.LeaseNumber= MerAppEqL.LeaseNumber
INNER JOIN Users USR ON STM.UserID = usr.UserID
WHERE MerAppEqL.FundedDate BETWEEN @x_strStartDate AND @x_strEndDate
AND MerAppEqL.LeaseStatus = 'Approved'

GROUP BY MerAppEql.SubmitBy, usr.FirstName, usr.LastName, MerApp.Assignedto
ORDER BY usr.FirstName, usr.LastName


Edited by - MuMu88 on 08/12/2013 11:27:33
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000