Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Macro substituion
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00840471
Message ID:
00889658
Views:
23
>>>>
>>>>You can build SQL statement as a local string variable and than run it using EXECUTE command or sp_executesq system sproc. For example,
DECLARE @Sql varchar(4000)
>>>>SET @Sql = 'SELECT fld1 FROM [' +  @lcTableName + ']'
>>>>EXECUTE (@Sql)
>>>
>>>How are you able to use '[' and ']' w/o getting an error?
>>
>>Why would I get an error? The square brackets are legitimate delimiters for SQL Server identifiers. The double quotes can also be used if SET QUOTED_IDENTIFIER is set to ON. See BOL for details.
>
>Not sure. This is what I get
>
>select * from userfl where userid=[MFA]
>Server: Msg 207, Level 16, State 3, Line 1
>Invalid column name 'MFA'.>
>
>but it works when I use
>
>
>select * from userfl where userid='MFA'>
In my select the square brackets were used as delimiters for a table name which is an SQL Server identifier (object name). The identifier delimiters are required if object name doesn't follow SQL Server names rules, for example, has spaces in it. In your select 'MFA' is a string literal and SQL Server supports only single quotes as string literal delimiters. Try
select * from [userfl] where userid='MFA'
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform