July 16, 2007 at 2:22 pm
I have the following query that uses @@ROWCOUNT
SELECT
TOP 1 SampleUnit_ID FROM #Sps
IF
@@ROWCOUNT = 0
BEGIN
-- Update #Log
INSERT INTO #Log (RecordType, RecordsValue)
Select 'No matching records were sampled for an HCAHPS unit.', LTRIM(STR(@@ROWCOUNT))
END
Unfortunately it is returning a data set when the entire SP is ran which I don't want
Is there a way to run something like
IF @@ROWCOUNT = SELECT TOP 1 sampleunit_id from #SPs
...
Thanks
July 16, 2007 at 2:39 pm
Try
IF NOT EXISTS ( SELECT 1 FROM #Sps)
BEGIN
....
END
July 16, 2007 at 2:56 pm
@@ROWCOUNT is highly volatile. Once referenced, it is reset.
IF @@ROWCOUNT = 0 -- Checked and reset.
INSERT ... VALUES (@@ROWCOUNT)
N 56°04'39.16"
E 12°55'05.25"
July 16, 2007 at 3:11 pm
So what do you suggest?
I need the Select Top 10 ... line to set the @@ROWCOUNT because it check the temp table to see if it has a record in it. But it returns a recordset which I don't want.
July 16, 2007 at 3:28 pm
Suggestion is already posted.
_____________
Code for TallyGenerator
July 16, 2007 at 5:52 pm
DECLARE @MyRows INT
SELECT TOP 1 SampleUnit_ID FROM #Sps
SET @MyRows = @@ROWCOUNT
IF @MyRows @@ROWCOUNT = 0
BEGIN
-- Update #Log
INSERT INTO #Log (RecordType, RecordsValue)
Select 'No matching records were sampled for an HCAHPS unit.', LTRIM(STR(@MyRows @@ROWCOUNT))
END
--Jeff Moden
Change is inevitable... Change for the better is not.
July 17, 2007 at 7:17 am
This worked like a champ. Thanks
July 17, 2007 at 7:24 am
You bet... thanks for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply