Share via

multi-part identifier "f.name" could not be bound

ACDBA 421 Reputation points
2022-10-27T14:42:35.953+00:00

Hi All,

I am running the below query to fetch inmemory file details using powershell.

SELECT getdate() as AuditTime,@@SERVERNAME AS InstanceName,DB_NAME() Database_Name,f.name,f.physical_name,fg.type_desc,* FROM sys.filegroups FG   
               JOIN sys.database_files F  
			     ON FG.data_space_id = F.data_space_id  
     WHERE FG.type = ''FX'' AND F.type = 2  

But it throws the below error on some instances.

Failed during execution | The multi-part identifier "f.name" could not be bound.

Can you please help?

Thanks,
ACDBA

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.


Answer accepted by question author

Ronen Ariely 15,221 Reputation points
2022-10-27T20:01:06.977+00:00

I am not sure that a "solution" without understanding have a lot of value since you will have such issue in the future.

The explanation is very simple

case sensitivity of Object names depend on the COLLATE

Here is a simple example of two databases. First one is using COLLATE which is Case Sensitive. Therefore we can create two tables named T and t. In this database you query will returns error since T and t are not the same.

create database Hebrew_100_CS_AS COLLATE Hebrew_100_CS_AS  
use Hebrew_100_CS_AS  
CREATE TABLE T(id int)  
CREATE TABLE t(id int)  
-- No issue using 2 object with the same name with upper and lower case  
-- Since the database COLLATE is case sensitive  
  
SELECT getdate() as AuditTime,@@SERVERNAME AS InstanceName,DB_NAME() Database_Name  
,f.name,f.physical_name,FG.type_desc,* FROM sys.filegroups FG  
JOIN sys.database_files F  
ON FG.data_space_id = F.data_space_id  
-- ERROR! The multi-part identifier "f.physical_name" could not be bound.  
----------------------------------------  
----------------------------------------  
create database Hebrew_100_CI_AS COLLATE Hebrew_100_CI_AS  
use Hebrew_100_CI_AS  
CREATE TABLE T(id int)  
CREATE TABLE t(id int)  
-- Error! There is already an object named 't' in the database.  

SELECT getdate() as AuditTime,@@SERVERNAME AS InstanceName,DB_NAME() Database_Name  
,f.name,f.physical_name,FG.type_desc,* FROM sys.filegroups FG  
JOIN sys.database_files F  
ON FG.data_space_id = F.data_space_id  
-- No error :-)   

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. Jingyang Li 5,901 Reputation points Volunteer Moderator
    2022-10-27T14:58:13.383+00:00

    SELECT getdate() as AuditTime,@@SERVERNAME AS InstanceName,DB_NAME() Database_Name
    ,F.name,F.physical_name,FG.type_desc,* FROM sys.filegroups FG
    JOIN sys.database_files F
    ON FG.data_space_id = F.data_space_id
    WHERE FG.type = ''FX'' AND F.type = 2

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.