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 2005 Forums
 Transact-SQL (2005)
 HI all

Author  Topic 

renu
Starting Member

47 Posts

Posted - 2008-01-28 : 01:10:25
i have a query like,

DECLARE @V1 VARCHAR(MAX)

set @v1 = 'SELECT * FROM table'

exec(@v1)

in this after execution if it returns any rows i should raiserror as pass if not i shoukd raiserror as failed.

how can i do that?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-28 : 01:39:56
Use:-
IF @@ROWCOUNT >0
RAISERROR ('Error blah blah', -- Message text.
16, -- Severity.
1 -- State.
);
Also why are you using dynamic sql for simple select?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-28 : 03:36:48
If you want to find the existance of the records

If exists(select * from table)
--do stuff
else
--do other stuff

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -