powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / hint OPTION(FORCE ORDER) in user-defined function:compilation error
4 сообщений из 4, страница 1 из 1
hint OPTION(FORCE ORDER) in user-defined function:compilation error
    #32067187
vantive
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
How to use hint OPTION(FORCE ORDER) in user-defined function?

create table a(i int ,val char )
create table b( i int, data char)
go
create function my_func (@v char)
returns table as
return ( select b.* from b JOIN a
ON a.id=b.id
OPTION(FORCE ORDER)
)
go
Output:
Server: Msg 156, Level 15, State 1, Procedure my_func, Line 5
Incorrect syntax near the keyword 'OPTION'.
...
Рейтинг: 0 / 0
hint OPTION(FORCE ORDER) in user-defined function:compilation error
    #32067190
Glory
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Choose in QA - Query - Show Execution Plan and check this script

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
select b.* from syscolumns b JOIN sysobjects a ON a.id=b.id 
select b.* from syscolumns b JOIN sysobjects a ON a.id=b.id OPTION(FORCE ORDER) 
go

if object_id('my_func') is not null drop function my_func
go
create function dbo.my_func() 
returns table as 
return(select b.* from syscolumns b JOIN sysobjects a ON a.id=b.id) 
go


select * from dbo.my_func()
select * from dbo.my_func() OPTION(FORCE ORDER) 
...
Рейтинг: 0 / 0
hint OPTION(FORCE ORDER) in user-defined function:compilation error
    #32067195
vantive
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Thanks, but ...
1) I want to hide this hint from users , which will use this function, it means I want keep hint in the body of function.
2) interesting point is that other hints, like NOLOCK, can
be embedded in user-defined function without any problem.

Thanks again
...
Рейтинг: 0 / 0
hint OPTION(FORCE ORDER) in user-defined function:compilation error
    #32067198
Glory
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
You can use several table hints in same query (for each table, join, ect.) but only one OPTION clause.

For example you can't create a view with OPTION clause. But you can create a view with several table hints.

So a think it's the feature. OPTION hint(s) should be used throughout the entire query . So it's impossible that something in FROM Clause (inline UDF, view) already contains OPTION hint(s).
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / hint OPTION(FORCE ORDER) in user-defined function:compilation error
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]