Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jrobin747
Starting Member
48 Posts |
Posted - 2013-08-12 : 10:26:20
|
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 namesSTM.UserID The multi-part identifier "STM.UserID" could not be boundMerAppEqL 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.UserIDWHERE MerAppEqL.FundedDate BETWEEN @x_strStartDate AND @x_strEndDate AND MerAppEqL.LeaseStatus = 'Approved'GROUP BY MerAppEql.SubmitBy, usr.FirstName, usr.LastName, MerApp.AssignedtoORDER BY usr.FirstName, usr.LastName |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-08-12 : 10:30:38
|
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.... |
|
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-08-12 : 11:26:33
|
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 namesSTM.UserID The multi-part identifier "STM.UserID" could not be boundMerAppEqL 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.UserIDWHERE MerAppEqL.FundedDate BETWEEN @x_strStartDate AND @x_strEndDate AND MerAppEqL.LeaseStatus = 'Approved'GROUP BY MerAppEql.SubmitBy, usr.FirstName, usr.LastName, MerApp.AssignedtoORDER BY usr.FirstName, usr.LastName
|
|
|
|
|
|
|
|