-3

My table alias is not working on SQL server 2012. I have enabled Intellisense. Still it's not working.

select * from department a -- Alias a should taken all columns automatically when I write:

select *
  from department a
 where a.departmentid = .. 

departmentid column have to come automatically when I write a.

Is there any setting I need to change in my server?

Regular Jo
  • 5,190
  • 3
  • 25
  • 47
Rajeev
  • 5
  • 2
  • 8
  • I don't understand what you are asking? adding the 'a' after a table name will let you reference that table with just 'a' in future... – dbajtr Jul 12 '17 at 12:41
  • Hi Rajeev, can you add the actual query where your are having errors? What error message are you getting? The syntax as you quote is looks OK, and should work. Please also edit your question to get rid of the repetition of your question. – Karel-Jan Misseghers Jul 12 '17 at 15:10
  • Considering the incomplete nature, this is a possible duplicate of [The multi-part identifier could not be bound](https://stackoverflow.com/questions/7314134/the-multi-part-identifier-could-not-be-bound) – Regular Jo Jan 20 '18 at 20:32

2 Answers2

0

The way you are describing it should work. This is basic TSQL, and the use of it cannot be disabled within SSMS.

Here is an example of the use of table aliases;

USE AdventureWorks2008R2;
GO
SELECT c.CustomerID, s.Name
FROM Sales.Customer c -- using 'AS'
JOIN Sales.Store AS s -- Not using 'AS'
ON c.CustomerID = s.BusinessEntityID ;

The use of AS is not mandatory.

If you are indeed running on SQL Server 2012, assuming that your are querying your database in SQL Server Management Studio, this syntax should definitely work.

  • Hi karel,Thank u for answering my question.this syntax is not working that makes me to post this question here.I think that i have to so some setting changes in sql server 2012 to make it possible..but i dont know what i have to exactly do...could some one help me to work it out.....Thank u... – Rajeev Jul 13 '17 at 07:37
0

Considering Rajeev's query is incomplete, this may or may not answer his problem, but as this is the first result in Google, I thought I would point people to Andriy M's answer on "The multi-part identifier could not be bound"

You are mixing implicit joins with explicit joins. That is allowed, but you need to be aware of how to do that properly.

Explicit: Joins involving the Join keyword.

The thing is, explicit joins (the ones that are implemented using the JOIN keyword) take precedence over implicit ones (the 'comma' joins, where the join condition is specified in the WHERE clause).

Regular Jo
  • 5,190
  • 3
  • 25
  • 47