Click here to Skip to main content
15,886,002 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

I have created a Procedure and i have used if exists to get the values.
SQL
SELECT * FROM MY_DATA WITH (NOLOCK) 
    IF @@ROWCOUNT>=1
        BEGIN
            SELECT * FROM MY_DETAIL WITH (NOLOCK)
        END
    ELSE
        BEGIN
            SELECT 'NO RECORDS'
        END

In this I have getting My_Data values plus My_detail table values.
But I want to get only My_Detail table value, how to avoid My_data records.
Kindly suggest for the same.
Posted

SQL
declare @count varchar(50)
select @count=count(1) from  MY_DATA WITH (NOLOCK) 
IF @count>=1
       BEGIN
           SELECT * FROM MY_DETAIL WITH (NOLOCK)
       END
   ELSE
       BEGIN
           SELECT 'NO RECORDS'
       END
 
Share this answer
 
Comments
Arunprasath Natarajan 20-Aug-12 7:55am    
Do I want to avoid @@Rowcount here?
Santhosh Kumar Jayaraman 20-Aug-12 7:58am    
If you use this,
SELECT * FROM MY_DATA WITH (NOLOCK)

you will get output of this.So instead of @@rowcount, i am gettin count .so only FROM select * from MY_DETAIL WITH (NOLOCK) will display records
Arunprasath Natarajan 20-Aug-12 8:03am    
Yeah I understand that, But what i am trying to ask is, At this conditions @@Rowcount is advisable or not. If yes, then is there any option to get the last query data alone.
Santhosh Kumar Jayaraman 20-Aug-12 8:06am    
No its not required..@count is enough
Arunprasath Natarajan 20-Aug-12 8:08am    
Tan q. will follow the same.
SQL
SELECT * FROM MY_DETAIL WITH (NOLOCK)
WHERE EXISTS (SELECT MAX(1) FROM MY_DATA WITH (NOLOCK) )
 
Share this answer
 

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