We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,231 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

sql search result

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

2
Contributors
2
Replies
1 Day
Discussion Span
5 Months Ago
Last Updated
3
Views
cyberdaemon
Junior Poster
125 posts since Nov 2010
Reputation Points: 11
Solved Threads: 2
Skill Endorsements: 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) 
AleMonteiro
Master Poster
752 posts since Aug 2010
Reputation Points: 129
Solved Threads: 140
Skill Endorsements: 23

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.

cyberdaemon
Junior Poster
125 posts since Nov 2010
Reputation Points: 11
Solved Threads: 2
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.5166 seconds using 2.65MB