Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 using insert into only when there re rows 2 insert

Author  Topic 

rtutus
Aged Yak Warrior

522 Posts

Posted - 2007-02-25 : 14:46:03
Hi, I use insert into like this, but when there re no rows returned by EXEC (@sql) I get the error :

There are no matching rows on which to report

and nothing after that in my query runs. Is there a way to avoid that pls? Here is that part of the query that causes the error:


SET @sql =' EXEC sys.sp_helprotect @username="' + @myVar
+ '"'

print @loginParam
INSERT INTO #permissions

(

[Owner],

[Object],

[Grantee],

[Grantor],

[ProtectType],

[Action],

[Column]

)

EXEC (@sql)

Kristen
Test

22859 Posts

Posted - 2007-02-25 : 15:20:29
Are you trying to do:

INSERT INTO #permissions(...)
EXEC sys.sp_helprotect ...

because if so that is not what your @sql is going to do!

Kristen
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2007-02-25 : 17:14:48
I just found it s funny actually, although i get the message There are no matching rows on which to report
my queries still execute it s just that my last statement select * from tempdb..#permissions to show the results does n t execute for some reason, so after runing my whole queries, I always have to run it again seperately to get the results of my query.
So there was no error :)
Thanks
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-02-26 : 06:18:33
Actually looking at your SQL again I think it will insert the rows into #permissions !!

But I reckon you could just do

INSERT INTO #permissions([Owner], [Object], [Grantee], [Grantor], [ProtectType], [Action], [Column])
EXEC sys.sp_helprotect @username = @myVar

Kristen
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2007-02-26 : 09:09:15
that s better then
Thank you Kristen :)
Go to Top of Page
   

- Advertisement -