Click here to Skip to main content
15,910,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
CREATE procedure [dbo].[ReportByDate]  
(  
 @StartDate DATE,  
 @EndDate DATE,
 @Email nvarchar(40)
 )  
as  
begin  
If exists(select 1 from tblWorkExpDetails)  
begin
select  
pd.FirstName,  
pd.LastName,  
pd.Mobile,  
pd.Email,  
pd.Sources,  
ed.XthPercentage,  
ed.XIIthPercentage,  
wed.CurrentSalary,  
wed.TotalExperience 
from  
tblPersonalDetails pd   
Inner Join tblEducationalDetails ed on pd.Email=ed.Email  
Inner Join tblWorkExpDetails wed on pd.Email=wed.Email  
where pd.JoinDate Between @StartDate and @EndDate  
end
else if exists(select 1 from tblFresherDetails)   
select   
pd.FirstName,  
pd.LastName,  
pd.Mobile,  
pd.Email,  
pd.Sources,  
ed.XthPercentage,  
ed.XIIthPercentage,  
fd.Typing   
from  

tblPersonalDetails pd   
Inner Join tblEducationalDetails ed on pd.Email=ed.Email  
Inner Join tblFresherDetails fd on pd.Email=fd.Email  
where pd.JoinDate Between @StartDate and @EndDate
end;    


--This query only returns those records which are present in tblWorkExpDetails table. Help me !
Posted
Updated 6-May-15 21:07pm
v2
Comments
CHill60 7-May-15 5:39am    
It's not clear what your question is.
If there are records on tblWorkExpDetails then you will never get to the query on tblFreshDetails because of the 'else'.
If you are trying to get all records from tblPersonalDetails regardless of whether there are records on tblWorkExpDetails then you need to use a LEFT OUTER join instead of the INNER join.
What is the actual problem?
ZurdoDev 7-May-15 16:58pm    
What is your question?

1 solution

Use this query to find the Table with Empty Rows in the Database:


SELECT sc.name +'.'+ ta.name TableName
,SUM(pa.rows) RowCnt
FROM sys.tables ta
INNER JOIN sys.partitions pa
ON pa.OBJECT_ID = ta.OBJECT_ID
INNER JOIN sys.schemas sc
ON ta.schema_id = sc.schema_id
WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)
GROUP BY sc.name,ta.name
having SUM(pa.rows)=0
ORDER BY SUM(pa.rows) DESC
 
Share this answer
 
Comments
CHill60 8-May-15 3:51am    
Doesn't help the OP much with their actual problem
Member 11039257 8-May-15 3:55am    
This is the actual solution for the Question u have asked..how to check empty table in sql server 2008?
State the clear question
CHill60 8-May-15 4:06am    
That was the title of the post. If you look at the body of the post the OP states "This query only returns those records which are present in tblWorkExpDetails table". Both RyanDev and I have asked the OP for clarification.
If you look carefully at the original post you will also realise that I did not ask the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900