1,105,625 Community Members

sql search result

Member Avatar
cyberdaemon
Junior Poster
125 posts since Nov 2010
Reputation Points: 1 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

good day,

i have a table named information
i created a stored procedure that will search for thier name, "firstname","middlename" and "lastname"

that 3 field is concatenated and named it fullname

My problem is that i want to count the result of my query that count the total number of return based on my condition. and if the result does not return a value, the message should be "RECORD NOT FOUND!"

here's my sample query for search

SELECT
            MRN
            ,CONVERT(DATE,BIRTHDATE)BIRTHDATE
            ,FIRSTNAME +' '+MIDDLENAME+' ' +LASTNAME as FULLNAME
            ,GENDER
            ,MARITAL_STATUS
            ,RELIGION
            ,OCCUPATION 
            ,ADDRESS1
    FROM [dbHIS].[dbo].[PATIENT_INFORMATION]


    WHERE (FIRSTNAME LIKE @FIRSTNAME OR @FIRSTNAME IS NULL)
            OR (LASTNAME LIKE @LASTNAME OR @LASTNAME IS NULL)
            OR (MIDDLENAME LIKE @MIDDLENAME OR @MIDDLENAME IS NULL) 

hope that some will help me.. thanks

Member Avatar
AleMonteiro
Master Poster
758 posts since Aug 2010
Reputation Points: 115 [?]
Q&As Helped to Solve: 143 [?]
Skill Endorsements: 29 [?]
 
0
 

I didn't understand much of what you want... but to get the count it would be:

DECLARE @rowsCount int

SELECT
    @rowsCount = count(*)
FROM 
    [dbHIS].[dbo].[PATIENT_INFORMATION]
WHERE
    (FIRSTNAME LIKE @FIRSTNAME OR @FIRSTNAME IS NULL)
    OR (LASTNAME LIKE @LASTNAME OR @LASTNAME IS NULL)
    OR (MIDDLENAME LIKE @MIDDLENAME OR @MIDDLENAME IS NULL) 
Member Avatar
cyberdaemon
Junior Poster
125 posts since Nov 2010
Reputation Points: 1 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Good day,

All i want is to get the total number of result based on my query. i want to display all the result in my gridview, if there's no result return i can make a decision to register the patient.

i'll try your codes later..

GOOD BLESS.
thank you for your reply.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: