Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create index in SQL Server table
Message
 
 
To
18/03/2020 11:38:11
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01673698
Message ID:
01673712
Views:
39
>>Could someone see what is wrong with the following SQL command? It works without an error when I run this command in the SSMS, but when I execute it from VFP 9, it give the error
>>
>>
>>The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common
>> table expressions, unless TOP or FOR XML is also specified
>>
>>
>>This is the SQL command:
>>
>>TEXT TO cSqlCommand TEXTMERGE NOSHOW
>>	IF NOT exists (SELECT sys.tables.name, sys.indexes.name, sys.columns.name FROM sys.indexes
>>        INNER JOIN sys.tables ON sys.tables.object_id = sys.indexes.object_id
>>        INNER JOIN sys.index_columns ON sys.index_columns.index_id = sys.indexes.index_id
>>            AND sys.index_columns.object_id = sys.tables.object_id
>>        INNER JOIN sys.columns ON sys.columns.column_id = sys.index_columns.column_id
>>            AND sys.columns.object_id = sys.tables.object_id
>>         WHERE sys.tables.name = 'MYTABLE' and sys.indexes.name = 'MYINDEX'
>>        ORDER BY
>>          sys.tables.name,
>>          sys.indexes.name,
>>          sys.columns.name )
>>		BEGIN
>>			CREATE NONCLUSTERED INDEX <<tcIndexTag>> ON [dbo].[<<tcTableName>>] ([<<tcFieldName>>])
>>	        SELECT CAST(1 AS bit) AS col_added
>>	    END    
>>	ELSE 
>>		SELECT CAST(0 AS bit) AS col_added
>>ENDTEXT
>>
>
>The order by is completely unnecessary in exists(...)... which doesn't care in which order it finds at least one record.

Thank you! This corrects the error.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform