Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

Simple T-SQL..

Please complete the following T-SQL per comments included.

Thank you.

SELECT
      CustomerID
      , FirstName
FROM tblCustomers
WHERE FirstName = 'Mike'

may return none, one, or multiple records. I want to findout how many. I know I can do something like:

SELECT Count(*) FROM tblCustomers WHERE FirstName = 'Mike'

but I am interested in finding out how a recordset/dataset object could be utilized here.

DECLARE @ID AS int                 -- store CustomerID in @ID
DECLARE @numberOfRecords AS int    -- number of records
-- DECLARE ds AS recordset         -- ds to store the select statement shown below??

-- look for CustomerIDs with first name Mike
SELECT 
	CustomerID
	, FirstName 
FROM tblCustomers 
WHERE FirstName = 'Mike'

-- not sure how this is done in T-SQL??
-- ds = SELECT CustomerID, ....

-- store number of records in ds??
-- Set  @numberOfRecords = ds.recordcount 

-- display @numberOfRecords
Select @numberOfRecords;

Open in new window

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

After the select, you simply use @@rowcount variable.
Set @yourvar = @@rowcount
ASKER CERTIFIED SOLUTION
Avatar of DcpKing
DcpKing
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial