Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
how to call procedure in diffrent connection if table exists and update shud be perforemed if table exists
Posted
Updated 12-Sep-13 18:07pm
v2
Comments
ArunRajendra 12-Sep-13 3:38am    
Is a & b are two different database?
[no name] 12-Sep-13 4:37am    
yes exactly 2 diffrent db

1 solution

you can try below code:-

SQL
IF exists (select * from  OPENDATASOURCE( 'SQLNCLI', 'Data Source= User ID=; Password=').DBName.dbo.TableName
 where id = object_id(N'[dbo].[TableName ]') and OBJECTPROPERTY(id, N'IsTable') = 1)
        Execute('select date from a.table1
                call table
                call proc with date parameter+1;')
ELSE
BEGIN
   call table;
   call proc with date parameter;
END
 
Share this answer
 
Comments
gvprabu 12-Sep-13 7:00am    
Nice Code.... my 5+
CHill60 12-Sep-13 7:52am    
Yes - like that.

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