SQL Server Error Msg 126 – Invalid pseudocolumn “%.*ls”.

In this blog post, let’s learn about the error message “126 – Invalid pseudocolumn “%.*ls”.” in Microsoft SQL Server, the reason why it appears and the solution to fix it.

SQL Server Error Message

126 – Invalid pseudocolumn “%.*ls”.

Reason for the Error

The SQL Server Error Msg 126 – Invalid pseudocolumn “%.*ls” occurs when you try to reference an invalid or non-existing pseudocolumn in a SQL query.

A pseudocolumn is a column that does not actually exist in a table but is available in SQL Server as a virtual column. These columns provide metadata or statistical information about the query result or other SQL Server functions. Some examples of pseudocolumns in SQL Server include @@ROWCOUNT, @@IDENTITY, @@SPID, and @@ERROR.

For instance, consider the following query in the AdventureWorks table

/****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP (1000) [DepartmentID]
      ,[Name]
      ,[GroupName]
      ,[ModifiedDate], $ROWCOUNT
  FROM [AdventureWorks2019].[HumanResources].[Department]

In this query, “$ROWCOUNT” is not a valid pseudocolumn name, and SQL Server will return the error message “Invalid pseudocolumn ‘%.*ls'” indicating that the pseudocolumn is not recognized.

Solution

To fix the issue, you need to use a valid pseudocolumn name or replace the pseudocolumn with an appropriate column name from the table.

For example, you can replace the invalid pseudocolumn with a valid pseudocolumn such as @@ROWCOUNT as follows:

/****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP (1000) [DepartmentID]
      ,[Name]
      ,[GroupName]
      ,[ModifiedDate], @@ROWCOUNT
  FROM [AdventureWorks2019].[HumanResources].[Department]

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this blog post, let’s learn about the error message “1459 – An error occurred while accessing the database mirroring...
In this blog post, let’s learn about the error message “7937 – Columnstore index has one or more missing column...