October 5, 2007 at 1:13 pm
Greetings,
So the stupid question of the moment is how can I make this work without doing the select statement the way I am?
SET @bLookForChangedCUSIPs = 0
SELECTCOUNT(*) ChangedCUSIPs
FROMPerformance.dbo.gChangedCUSIPs
WHERECUSIPKey = @vchVAGK+@vchPAC
IF @@ROWCOUNT>0 SET @bLookForChangedCUSIPs = 1
Ultimately I am just trying to set a flag. Of course, the problem is that I get a returned row from the select statement which while it doesn't do anything to the application it is in just looks like crud. I have alot of these little flag tests so I dont really want to use a procedure with OUTPUT.
Any thoughts?
thanks,
Chris
October 5, 2007 at 1:45 pm
change this:
SET @bLookForChangedCUSIPs = 0
SELECTCOUNT(*) ChangedCUSIPs
FROMPerformance.dbo.gChangedCUSIPs
WHERECUSIPKey = @vchVAGK+@vchPAC
IF @@ROWCOUNT>0 SET @bLookForChangedCUSIPs = 1
to this:
set @bLookForChangedCUSIPs
select @bLookForChangedCUSIPs = 1 from Performance.dbo.gChangedCUSIPs WHERE CUSIPKey = @vchVAGK+@vchPAC
😎
October 5, 2007 at 2:34 pm
cool, thanks 🙂
October 6, 2007 at 3:07 pm
Or, just...
SELECT @bLookForChangedCUSIPs = SIGN(COUNT(*))
FROM Performance.dbo.gChangedCUSIPs
WHERE CUSIPKey = @vchVAGK + @vchPAC
--Jeff Moden
Change is inevitable... Change for the better is not.
October 8, 2007 at 2:49 am
COUNT needs to scan the whole table.
Try this!
IF EXISTS (SELECT * FROM Performance.dbo.gChangedCUSIPs WHERE CUSIPKey = @vchVAGK + @vchPAC)
SET @bLookForChangedCUSIPs = 1
ELSE
SET @bLookForChangedCUSIPs = 0
N 56°04'39.16"
E 12°55'05.25"
October 8, 2007 at 5:18 pm
Even better!
--Jeff Moden
Change is inevitable... Change for the better is not.
October 8, 2007 at 5:19 pm
Nice one, Peter.
October 9, 2007 at 12:20 am
Thank you!
N 56°04'39.16"
E 12°55'05.25"
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply