Mar 24, 2014

Cannot call methods on Sql server

Suppose we have created a table User in sql server:

    [User_Id] BIGINT

Now I want to select records from User table:

SELECT User.[User_Id] FROM [User]

We will get error message:

Cannot call methods on nvarchar.

Cause:  Sql sever User is reserved word. In this query sql sever is not thinking User is a table name.


1. Use [] or "" in table name. For example:  

SELECT [User].[User_Id] FROM [User]

SELECT "USER".[User_Id] FROM [User]

2. Use table alias. For example:

SELECT ur.[User_Id] FROM [User] ur

No comments: