Link to home
Start Free TrialLog in
Avatar of rafaelrgl
rafaelrgl

asked on

insert does not work with newid()

hi, can someone make this query works,

insert int @table1(id)
set rowcount 1
select t1.id from tb_test
order by newid()

that's any simply example of my quer. but if we do the syntax for this one i can do on mine.
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

You probably need something more like this:

set rowcount 1
insert into @table1(id)
select t1.id from tb_test t1
order by newid()

not real sure what you are trying to do though
Avatar of rafaelrgl
rafaelrgl

ASKER

i am trying to put this inside an function, but it does not execute, shows an error saying:

invalid use of a side-effecting operator 'SET ROW COUNT' whithin a function .
invalid use of a side-effecting operator 'newid' within a function.


:(
SOLUTION
Avatar of Anuj
Anuj
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it needs to be an function, but how do i select random rows without using rowcount?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial