|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
@@rowcount without displaying selectIf i do the following in a trigger: select * from <table> where <condition> if @@rowcount > 0 begin <perform tasks> end .... but im not necessarily interested in displaying a rowset. The above select statement will return a rowset for display wont it? Isnt there any way to determine if @@rowcount > 0 without using a select? Im guessing a select is harmful in some way as it returns a displayed row. But im not interested in displaying the reulting row, I just want to know if there is such a row. What impact dows the select statement have, given the fact im not interested in the content of that particular row? Any help most appreciated. Cheers, peter IF EXISTS
( SELECT 1 FROM <table> WHERE <condition> ) BEGIN PRINT 'There was at least one row.'; END Show quoteHide quote "peter walker" <p.walker@nospam.com> wrote in message news:%23xei3EeoGHA.148@TK2MSFTNGP04.phx.gbl... > Hi, im hoping someone could shed some insight. > > If i do the following in a trigger: > > select * from <table> where <condition> > > if @@rowcount > 0 > begin > <perform tasks> > end > > ... but im not necessarily interested in displaying a rowset. The above > select statement will return a rowset for display wont it? Isnt there any > way to determine if @@rowcount > 0 without using a select? Im guessing a > select is harmful in some way as it returns a displayed row. But im not > interested in displaying the reulting row, I just want to know if there is > such a row. What impact dows the select statement have, given the fact im > not interested in the content of that particular row? > > Any help most appreciated. > > Cheers, > peter > Peter,
You could use this instead... If (select Count(*) from <table> where <condition>) > 0 begin <perform tasks> end HTH Barry Throw the count into a variable
declare @rowcount int select @rowcount = count(*) from <table> where <condition> if @rowcount > 0 ..... ... .. Denis the SQL Menace http://sqlservercode.blogspot.com/ peter walker wrote: Show quoteHide quote > Hi, im hoping someone could shed some insight. > > If i do the following in a trigger: > > select * from <table> where <condition> > > if @@rowcount > 0 > begin > <perform tasks> > end > > ... but im not necessarily interested in displaying a rowset. The above > select statement will return a rowset for display wont it? Isnt there any > way to determine if @@rowcount > 0 without using a select? Im guessing a > select is harmful in some way as it returns a displayed row. But im not > interested in displaying the reulting row, I just want to know if there is > such a row. What impact dows the select statement have, given the fact im > not interested in the content of that particular row? > > Any help most appreciated. > > Cheers, > peter or better yet
if exists (select * from <table> where <condition>) begin <perform tasks> end Denis the SQL Menace http://sqlservercode.blogspot.com/ peter walker wrote: Show quoteHide quote > Hi, im hoping someone could shed some insight. > > If i do the following in a trigger: > > select * from <table> where <condition> > > if @@rowcount > 0 > begin > <perform tasks> > end > > ... but im not necessarily interested in displaying a rowset. The above > select statement will return a rowset for display wont it? Isnt there any > way to determine if @@rowcount > 0 without using a select? Im guessing a > select is harmful in some way as it returns a displayed row. But im not > interested in displaying the reulting row, I just want to know if there is > such a row. What impact dows the select statement have, given the fact im > not interested in the content of that particular row? > > Any help most appreciated. > > Cheers, > peter Try this:
IF EXISTS(SELECT 1 FROM <table> WHERE <condition>) BEGIN <perform tasks> END HTH Vern Rabe Show quoteHide quote "peter walker" wrote: > Hi, im hoping someone could shed some insight. > > If i do the following in a trigger: > > select * from <table> where <condition> > > if @@rowcount > 0 > begin > <perform tasks> > end > > .... but im not necessarily interested in displaying a rowset. The above > select statement will return a rowset for display wont it? Isnt there any > way to determine if @@rowcount > 0 without using a select? Im guessing a > select is harmful in some way as it returns a displayed row. But im not > interested in displaying the reulting row, I just want to know if there is > such a row. What impact dows the select statement have, given the fact im > not interested in the content of that particular row? > > Any help most appreciated. > > Cheers, > peter > > > peter walker wrote:
Show quoteHide quote > Hi, im hoping someone could shed some insight. As others have replied, you can use IF EXISTS or COUNT(*). Depending on > > If i do the following in a trigger: > > select * from <table> where <condition> > > if @@rowcount > 0 > begin > <perform tasks> > end > > ... but im not necessarily interested in displaying a rowset. The above > select statement will return a rowset for display wont it? Isnt there any > way to determine if @@rowcount > 0 without using a select? Im guessing a > select is harmful in some way as it returns a displayed row. But im not > interested in displaying the reulting row, I just want to know if there is > such a row. What impact dows the select statement have, given the fact im > not interested in the content of that particular row? > > Any help most appreciated. > > Cheers, > peter > > what you're doing in <perform tasks>, you might be able to avoid even doing such a check. If <perform tasks> is merely another query, you may be able to JOIN your check table, or use EXISTS in the where clause.
Deadlock
Updating Tables in SQL Express smalldatetime conversion error Cursor Question DDL and DML in same stored procedure drop a not null field Efficient update of column based on earlier records. performance: table value UDF vs view How Can I access SQL Server SMO Objects in VB6 problem with combining data (join /union) |
|||||||||||||||||||||||