exec и работа с возвращаемыми значениями
azarny
Дата: 04.12.2002 19:03:58
Доброго времени суток !
Есть функция
create function dscontains (@contentsfilter varchar(200))
RETURNS @ret table (did int)
AS begin
declare @ds varchar(8000)
-- просто дял примера
set @ds = 'select doc.id from doc'
exec @ds
.....
end |
|
как правильно заполнить таблицу возвращаемого значения ?
Александр Азаркович
Дата: 05.12.2002 11:02:01
А Вы чего хотите получить-то?
Если я правильно понял, динамически формировать запрос в теле функции?
Но в функции можно делать EXEC только хранимой процедуре! Вам нужно какое-то иное решение искать.
azarny
Дата: 05.12.2002 11:30:59
Из функцтт sp не вызываются
tygra
Дата: 05.12.2002 12:00:38
как правильно заполнить таблицу возвращаемого значения ?
Так же, как и любую другую.
azarny
Дата: 05.12.2002 12:25:10
Код в студию !
Gulchatay
Дата: 05.12.2002 14:45:28
declare @proc nvarchar(300)
set @proc='select * from test'
exec (@proc)
azarny
Дата: 05.12.2002 15:23:43
Так , дамы и господа.
НЕ НАДО ПИСАТЬ ОТВЕТЫ НА ТОГО ЧЕГО НЕ ЗНАЕТЕ !
Специально для Гюльчатай - попробуй откомпили свои записки.
create table thetest (id int)
go
insert into thetest(id) values (1)
insert into thetest(id) values (2)
insert into thetest(id) values (3)
go
create function fthetest(@ttestparam varchar(200))
returns @ret table (id int)
as begin
declare @proc nvarchar(300)
set @proc='select id from test'
exec (@proc)
return
end |
|
Александр Азаркович
Дата: 05.12.2002 16:21:48
Сударь! (сударыня?)
Вы, прежде чем шуметь, объясните по-человечески, чего хотите получить!
Вам написали кусок кода, а Вы его вставляете зачем-то в функцию и говорите "не компилится". Ну и не будет!
azarny
Дата: 05.12.2002 16:48:53
Добрый вечер всем.
Берем для примера предыдущий код.
Хочется получить : результат исполнения значения переменной @proc в @ret вот и все.
Пиво и/или слоники - без вопросов, для тех кто напишет решение.
create table thetest (id int)
go
insert into thetest(id) values (1)
insert into thetest(id) values (2)
insert into thetest(id) values (3)
go
create function fthetest(@ttestparam varchar(200))
returns @ret table (id int)
as begin
declare @proc nvarchar(300)
-- здесь реально select создается на лету и заранее он не известен
-- %af_src_str_0 - просто пример
set @proc='select id from test'
-- здесь ошибка при компиляции
exec (@proc)
-- и этот вариант на этапе выполнения не проходит
--exec @proc
return
end |
|
Александр Азаркович
Дата: 05.12.2002 17:21:26
BOL -> Transact-SQL Reference -> CREATE FUNCTION
The following statements are allowed in the body of a multi-statement function. Statements not in this list are not allowed in the body of a function:
* Assignment statements.
* Control-of-Flow statements.
* DECLARE statements defining data variables and cursors that are local to the function.
* SELECT statements containing select lists with expressions that assign values to variables that are local to the function.
* Cursor operations referencing local cursors that are declared, opened, closed, and deallocated in the function. Only FETCH statements that assign values to local variables using the INTO clause are allowed; FETCH statements that return data to the client are not allowed.
* INSERT, UPDATE, and DELETE statements modifying table variables local to the function.
* EXECUTE statements calling an extended stored procedures.
Таким образом, через функцию - не получится...